forked from CopilotKit/CopilotKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathagentspec_agent.py
More file actions
87 lines (73 loc) · 2.36 KB
/
Copy pathagentspec_agent.py
File metadata and controls
87 lines (73 loc) · 2.36 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
81
82
83
84
85
86
87
from __future__ import annotations
import os
from typing import Dict, Any
import dotenv
dotenv.load_dotenv()
from pyagentspec.agent import Agent
from pyagentspec.llms import OpenAiCompatibleConfig
from pyagentspec.tools import ServerTool, ClientTool
from pyagentspec.property import Property
from pyagentspec.serialization import AgentSpecSerializer
def get_weather(location: str) -> Dict[str, Any]:
"""
Get the weather for a given location.
"""
import time
time.sleep(1) # simulates real tool execution
return {
"temperature": 20,
"conditions": "sunny",
"humidity": 50,
"wind_speed": 10,
"feelsLike": 25,
}
weather_tool = ServerTool(
name="get_weather",
description="Get the weather for a given location.",
inputs=[
Property(
title="location",
json_schema={
"title": "location",
"type": "string",
"description": "The location to get the weather forecast. Must be a city/town name.",
},
)
],
outputs=[
Property(
title="weather_result",
json_schema={"title": "weather_result", "type": "string"},
)
],
)
go_to_moon_tool = ClientTool(
name="go_to_moon",
description="Go to the moon on request.",
)
setThemeColor_tool = ClientTool(
name="setThemeColor",
description="Change the theme color of the chat. Can be anything that the CSS background attribute accepts. Regular colors, linear of radial gradients etc.",
inputs=[
Property(
title="themeColor",
json_schema={
"title": "themeColor",
"type": "string",
"description": "The theme color to set. Make sure to pick nice colors.",
},
)
],
)
with_agentspec_agent = Agent(
name="AgentSpecAgent",
description="A starter Agent that can call tools.",
system_prompt="You are a helpful assistant, named Specky, that has access to some tools.",
llm_config=OpenAiCompatibleConfig(
name="with-agentspec-agent",
model_id=os.getenv("OPENAI_MODEL", "gpt-4o"),
url=os.getenv("OPENAI_BASE_URL", "https://api.openai.com/v1"),
),
tools=[weather_tool, go_to_moon_tool, setThemeColor_tool],
)
with_agentspec_agent_json = AgentSpecSerializer().to_json(with_agentspec_agent)