forked from Arize-ai/openinference
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreact_agent.py
More file actions
46 lines (34 loc) · 1.19 KB
/
react_agent.py
File metadata and controls
46 lines (34 loc) · 1.19 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
import asyncio
import sys
import traceback
from beeai_framework.agents.react import ReActAgent
from beeai_framework.backend.chat import ChatModel
from beeai_framework.backend.types import ChatModelParameters
from beeai_framework.errors import FrameworkError
from beeai_framework.memory import TokenMemory
from beeai_framework.tools.search.duckduckgo import DuckDuckGoSearchTool
from beeai_framework.tools.tool import AnyTool
from beeai_framework.tools.weather.openmeteo import OpenMeteoTool
from examples.setup import setup_observability
setup_observability()
llm = ChatModel.from_name(
"ollama:granite3.3",
ChatModelParameters(temperature=0),
)
tools: list[AnyTool] = [
OpenMeteoTool(),
DuckDuckGoSearchTool(),
]
agent = ReActAgent(llm=llm, tools=tools, memory=TokenMemory(llm))
prompt = "What's the current weather in Las Vegas?"
async def main() -> None:
response = await agent.run(
prompt, max_retries_per_step=3, total_max_retries=10, max_iterations=20
)
print("Agent 🤖 : ", response.last_message.text)
if __name__ == "__main__":
try:
asyncio.run(main())
except FrameworkError as e:
traceback.print_exc()
sys.exit(e.explain())