parent
03e0a3bded
commit
931c967fc5
@ -0,0 +1,47 @@
|
||||
from swarms.structs import Task, Agent
|
||||
from swarms.models import OpenAIChat
|
||||
from dotenv import load_dotenv
|
||||
import os
|
||||
|
||||
|
||||
# Load the environment variables
|
||||
load_dotenv()
|
||||
|
||||
|
||||
# Define a function to be used as the action
|
||||
def my_action():
|
||||
print("Action executed")
|
||||
|
||||
|
||||
# Define a function to be used as the condition
|
||||
def my_condition():
|
||||
print("Condition checked")
|
||||
return True
|
||||
|
||||
|
||||
# Create an agent
|
||||
agent = Agent(
|
||||
llm=OpenAIChat(openai_api_key=os.environ["OPENAI_API_KEY"]),
|
||||
max_loops=1,
|
||||
dashboard=False,
|
||||
)
|
||||
|
||||
# Create a task
|
||||
task = Task(description="What's the weather in miami", agent=agent)
|
||||
|
||||
# Set the action and condition
|
||||
task.set_action(my_action)
|
||||
task.set_condition(my_condition)
|
||||
|
||||
# Execute the task
|
||||
print("Executing task...")
|
||||
task.run()
|
||||
|
||||
# Check if the task is completed
|
||||
if task.is_completed():
|
||||
print("Task completed")
|
||||
else:
|
||||
print("Task not completed")
|
||||
|
||||
# Output the result of the task
|
||||
print(f"Task result: {task.result}")
|
Loading…
Reference in new issue