-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic_agent.py
More file actions
28 lines (21 loc) · 799 Bytes
/
basic_agent.py
File metadata and controls
28 lines (21 loc) · 799 Bytes
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
from llama_index.llms.openai import OpenAI
from llama_index.core.agent.workflow import AgentWorkflow
OPENAI_APIKEY="Your APIKEY here!"
def multiply(a: float, b: float) -> float:
"""Multiply two numbers and returns the product"""
return a * b
def add(a: float, b: float) -> float:
"""Add two numbers and returns the sum"""
return a + b
llm = OpenAI(model="gpt-4o-mini", api_key=OPENAI_APIKEY)
workflow = AgentWorkflow.from_tools_or_functions(
[multiply, add],
llm=llm,
system_prompt="You are an agent that can perform basic mathematical operations using tools."
)
async def main():
response = await workflow.run(user_msg="What is 40+(5*10)?")
print(response)
if __name__ == "__main__":
import asyncio
asyncio.run(main())