기본 에이전트 구축하기
질문에 답하고 도구를 호출할 수 있는 간단한 에이전트를 만들어 보겠습니다. 이 에이전트는 언어 모델로 Claude Sonnet 4.5를 사용하고, 도구로 기본적인 날씨 함수를 사용하며, 동작을 안내하는 간단한 프롬프트를 사용합니다.이 예제를 실행하려면 Claude (Anthropic) 계정을 설정하고 API 키를 발급받아야 합니다. 그런 다음 터미널에서
ANTHROPIC_API_KEY 환경 변수를 설정하세요.실전 에이전트 구축하기
이제 주요 프로덕션 개념을 보여주는 실용적인 날씨 예보 에이전트를 구축해 보겠습니다:- 상세한 시스템 프롬프트로 더 나은 에이전트 동작 구현
- 외부 데이터와 통합되는 도구 생성
- 일관된 응답을 위한 모델 구성
- 예측 가능한 결과를 위한 구조화된 출력
- 대화형 상호작용을 위한 대화 메모리
- 완전히 기능하는 에이전트 생성 및 실행
1
시스템 프롬프트 정의하기
시스템 프롬프트는 에이전트의 역할과 동작을 정의합니다. 구체적이고 실행 가능하게 작성하세요:
2
도구 생성하기
Tools are functions your agent can call. Oftentimes tools will want to connect to external systems, and will rely on runtime configuration to do so. Notice here how the
getUserLocation tool does exactly that:Zod is a library for validating and parsing pre-defined schemas. You can use it to define the input schema for your tools to make sure the agent only calls the tool with the correct arguments.Alternatively, you can define the
schema property as a JSON schema object. Keep in mind that JSON schemas won’t be validated at runtime.Example: Using JSON schema for tool input
Example: Using JSON schema for tool input
3
Configure your model
Set up your language model with the right parameters for your use case:
4
Define response format
Optionally, define a structured response format if you need the agent responses to match
a specific schema.
5
Add memory
Add memory to your agent to maintain state across interactions. This allows
the agent to remember previous conversations and context.
In production, use a persistent checkpointer that saves to a database.
See Add and manage memory for more details.
6
Create and run the agent
Now assemble your agent with all the components and run it!
- Understand context and remember conversations
- Use multiple tools intelligently
- Provide structured responses in a consistent format
- Handle user-specific information through context
- Maintain conversation state across interactions
Connect these docs programmatically to Claude, VSCode, and more via MCP for real-time answers.