forked from bengeos/llmstitch
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic.py
More file actions
45 lines (32 loc) · 1.17 KB
/
Copy pathbasic.py
File metadata and controls
45 lines (32 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
"""Minimal llmstitch example: one tool, the Anthropic adapter, a single run.
Usage:
pip install "llmstitch[anthropic]"
ANTHROPIC_API_KEY=... python examples/basic.py
"""
from __future__ import annotations
import asyncio
import os
from llmstitch import Agent, tool
from llmstitch.providers.anthropic import AnthropicAdapter
@tool
def get_weather(city: str) -> str:
"""Return a canned weather report for the given city."""
return f"{city}: 72°F and sunny"
async def main() -> None:
if not os.environ.get("ANTHROPIC_API_KEY"):
raise SystemExit("ANTHROPIC_API_KEY not set")
agent = Agent(
provider=AnthropicAdapter(),
model="claude-haiku-4-5-20251001",
system="You are a helpful weather assistant. Use the tool when asked about a city.",
)
agent.tools.register(get_weather)
history = await agent.run("What's the weather in Addis Ababa?")
final = history[-1]
if isinstance(final.content, list):
from llmstitch.types import TextBlock
print("".join(b.text for b in final.content if isinstance(b, TextBlock)))
else:
print(final.content)
if __name__ == "__main__":
asyncio.run(main())