from picoagents import Agent, OpenAIChatCompletionClient
import asyncio
def get_weather(location):
# This is a mock function. In a real implementation, this would call a weather API.
return f"The current weather in {location} is sunny with a temperature of 25°C."
agent = Agent(
name="assistant",
description="You are a helpful assistant.",
instructions="Your are helpful. Use tools when appropriate.",
model_client=OpenAIChatCompletionClient(
model="gpt-4.1-mini",
api_key="your-openai-api-key"
),
tools=[get_weather]
)
async def main():
print("=== Basic Agent Example ===\n")
print(f"Agent: {agent.name}")
print(f"Tools: {[tool.name for tool in agent.tools]}\n")
async for event in agent.run_stream("What is the weather like in New York?"):
print(event)
if __name__ == "__main__":
asyncio.run(main())
python chapter_4/main.py
Traceback (most recent call last):
File "/home/shahriyarrzayev/REPOS/Others/AI-Agents/multi_agent_systems_book/.venv/lib/python3.12/site-packages/picoagents/llm/_anthropic.py", line 15, in <module>
from anthropic import (
ModuleNotFoundError: No module named 'anthropic'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/shahriyarrzayev/REPOS/Others/AI-Agents/multi_agent_systems_book/chapter_4/main.py", line 1, in <module>
from picoagents import Agent, OpenAIChatCompletionClient
File "/home/shahriyarrzayev/REPOS/Others/AI-Agents/multi_agent_systems_book/.venv/lib/python3.12/site-packages/picoagents/__init__.py", line 62, in <module>
from .agents import (
File "/home/shahriyarrzayev/REPOS/Others/AI-Agents/multi_agent_systems_book/.venv/lib/python3.12/site-packages/picoagents/agents/__init__.py", line 8, in <module>
from ._agent import Agent
File "/home/shahriyarrzayev/REPOS/Others/AI-Agents/multi_agent_systems_book/.venv/lib/python3.12/site-packages/picoagents/agents/_agent.py", line 40, in <module>
from ._base import AgentToolError, BaseAgent
File "/home/shahriyarrzayev/REPOS/Others/AI-Agents/multi_agent_systems_book/.venv/lib/python3.12/site-packages/picoagents/agents/_base.py", line 20, in <module>
from ..llm import BaseChatCompletionClient
File "/home/shahriyarrzayev/REPOS/Others/AI-Agents/multi_agent_systems_book/.venv/lib/python3.12/site-packages/picoagents/llm/__init__.py", line 8, in <module>
from ._anthropic import AnthropicChatCompletionClient
File "/home/shahriyarrzayev/REPOS/Others/AI-Agents/multi_agent_systems_book/.venv/lib/python3.12/site-packages/picoagents/llm/_anthropic.py", line 25, in <module>
raise ImportError(
ImportError: Anthropic library not installed. Please install with: pip install anthropic>=0.73.0
Slightly changed version of Listing 4.1:
Dependency issue: