Part 2: Giving Agents Tools and Memory
The Tool Problem I Kept Hitting
What Is a Tool?
Defining Tools with JSON Schema
# tools.py
from __future__ import annotations
import asyncio
import json
from dataclasses import dataclass
from typing import Any, Awaitable, Callable
@dataclass
class ToolDefinition:
name: str
description: str
parameters: dict[str, Any] # JSON Schema object
fn: Callable[..., Awaitable[str]]
def to_dict(self) -> dict[str, Any]:
"""Schema representation sent to OpenAI / Anthropic."""
return {
"name": self.name,
"description": self.description,
"parameters": self.parameters,
}The Tool Dispatcher
Short-Term vs Long-Term Memory
Pattern A: Shared Context Dict (in-process)
Pattern B: SQLite for Persistence
Wiring It Together: An Agent with Tools and Persistence
Sharing Context Between Two Agents
Key Takeaways
Up Next
PreviousPart 1: Building Agents from Scratch in Python 3NextPart 3: Orchestrating Agents with OpenAI
Last updated