Overview
This reference documents the core agent implementation patterns used throughout the Building Reliable Agents course. The implementations demonstrate how to build conversational AI agents using OpenAI’s Chat Completions API with tool calling capabilities.Basic Agent Pattern
The simplest agent implementation accepts a question and returns a response.agent()
Basic agent function with tool calling support.
str
required
User’s question or input message
str
The agent’s final response message
list[dict]
Complete conversation history including:
- User messages
- Assistant messages
- Tool calls and results
Conversational Agent with Thread History
Agents that maintain conversation history across multiple turns.chat_pipeline()
Agent function with persistent conversation history using thread storage.
list[dict]
required
New messages to add to the conversation. Each message should have:
role: “user” or “assistant”content: The message text
list[dict]
Complete conversation history including all previous messages and the new response
get_thread_history()
Retrieve conversation history for a specific thread.
str
required
Unique identifier for the conversation thread
list[dict]
List of all messages in the thread
save_thread_history()
Save conversation history for a thread.
str
required
Unique identifier for the conversation thread
list[dict]
required
Complete message history to save
Advanced Agent with Multiple Tools
chat()
Full-featured async agent with multiple tools and conversation history.
str
required
User’s question or input message
list[dict]
Complete conversation history including system prompt, user messages, assistant responses, and tool calls
str
The agent’s final response message
- Async/await support for concurrent operations
- Multiple tool support (database queries, knowledge base search)
- System prompt with detailed instructions
- Conversation history management
- Agentic tool calling loop (continues until no more tool calls)
Best Practices
LangSmith Tracing
Always use the@traceable decorator for observability:
Error Handling
Handle tool execution errors gracefully:Thread Management
In production, use a database instead of in-memory storage:System Prompts
Keep system prompts separate and version controlled:Related
- Tool Functions - Database and knowledge base tools
- Evaluators - Testing and evaluation functions