이 가이드는 계획, 파일 시스템 도구, 그리고 subagent 기능을 갖춘 첫 번째 deep agent를 만드는 과정을 안내합니다. 연구를 수행하고 보고서를 작성할 수 있는 연구 agent를 구축하게 됩니다.

사전 요구사항

시작하기 전에 모델 제공자(예: Anthropic, OpenAI)로부터 API key를 받았는지 확인하세요.

Step 1: 의존성 설치

pip install deepagents tavily-python

Step 2: API key 설정

export ANTHROPIC_API_KEY="your-api-key"
export TAVILY_API_KEY="your-tavily-api-key"

Step 3: 검색 도구 생성

import os
from typing import Literal
from tavily import TavilyClient
from deepagents import create_deep_agent

tavily_client = TavilyClient(api_key=os.environ["TAVILY_API_KEY"])

def internet_search(
    query: str,
    max_results: int = 5,
    topic: Literal["general", "news", "finance"] = "general",
    include_raw_content: bool = False,
):
    """Run a web search"""
    return tavily_client.search(
        query,
        max_results=max_results,
        include_raw_content=include_raw_content,
        topic=topic,
    )

Step 4: Deep agent 생성

# System prompt to steer the agent to be an expert researcher
research_instructions = """You are an expert researcher. Your job is to conduct thorough research and then write a polished report.

You have access to an internet search tool as your primary means of gathering information.

## `internet_search`

Use this to run an internet search for a given query. You can specify the max number of results to return, the topic, and whether raw content should be included.
"""

agent = create_deep_agent(
    tools=[internet_search],
    system_prompt=research_instructions
)

Step 5: Agent 실행

result = agent.invoke({"messages": [{"role": "user", "content": "What is langgraph?"}]})

# Print the agent's response
print(result["messages"][-1].content)

무슨 일이 일어났나요?

Deep agent가 자동으로 다음을 수행했습니다:
  1. 접근 방식 계획: 내장된 write_todos 도구를 사용하여 연구 작업을 세분화
  2. 연구 수행: internet_search 도구를 호출하여 정보 수집
  3. 컨텍스트 관리: 파일 시스템 도구(write_file, read_file)를 사용하여 대용량 검색 결과 오프로드
  4. Subagent 생성 (필요한 경우): 복잡한 하위 작업을 전문화된 subagent에 위임
  5. 보고서 종합: 조사 결과를 일관성 있는 응답으로 컴파일

다음 단계

첫 번째 deep agent를 구축했으니 이제:
  • Agent 커스터마이징: 커스텀 system prompt, 도구, subagent를 포함한 커스터마이징 옵션에 대해 알아보세요.
  • Middleware 이해하기: Deep agent를 구동하는 middleware 아키텍처를 자세히 살펴보세요.
  • 장기 메모리 추가: 대화 전반에 걸친 영구 메모리를 활성화하세요.
  • 프로덕션 배포: LangGraph 애플리케이션을 위한 배포 옵션에 대해 알아보세요.

Connect these docs programmatically to Claude, VSCode, and more via MCP for real-time answers.
I