-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathagent_tools.py
More file actions
80 lines (64 loc) · 1.99 KB
/
Copy pathagent_tools.py
File metadata and controls
80 lines (64 loc) · 1.99 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
"""
Tara /agent with a single tool — shows the request shape but does NOT loop.
After running this you'll see a response with stop_reason="tool_use" and
a tool_use content block. To actually complete the round-trip and get
Tara's final answer, see agent_loop.py.
Usage:
export TARA_API_KEY=tara_sk_...
python agent_tools.py
"""
from __future__ import annotations
import json
import os
import requests
TARA_API_BASE = "https://tara.tratok.com/api/v1"
TOOLS = [
{
"name": "get_weather",
"description": (
"Get the current weather for a city. "
"Returns temperature in celsius and a one-word condition "
"(sunny/cloudy/rainy/snowy)."
),
"input_schema": {
"type": "object",
"properties": {
"city": {
"type": "string",
"description": "City name in English, e.g. 'Dubai'.",
},
},
"required": ["city"],
},
}
]
def call_agent_with_tools() -> dict:
api_key = os.environ.get("TARA_API_KEY")
if not api_key:
raise SystemExit("Set TARA_API_KEY in your environment first.")
response = requests.post(
f"{TARA_API_BASE}/agent.php",
headers={
"Authorization": f"Bearer {api_key}",
"Content-Type": "application/json",
},
json={
"messages": [
{"role": "user", "content": "What is the weather like in Dubai right now?"}
],
"tools": TOOLS,
"max_tokens": 1024,
},
timeout=60,
)
response.raise_for_status()
return response.json()
def main() -> None:
result = call_agent_with_tools()
print(json.dumps(result, indent=2))
print()
print(f"--- stop_reason={result['stop_reason']}")
if result["stop_reason"] == "tool_use":
print("→ Tara wants to call a tool. See agent_loop.py for the full round-trip.")
if __name__ == "__main__":
main()