We’ll build a simple agent that uses tasks to write a short story.
Agent YAML
Copy
name: Story Generatormodel: claude-3.5-sonnetabout: A helpful AI assistant that specializes in writing and editing.
Task YAML
Copy
name: Write a short storydescription: Write a short story about a magical gardenmain:- prompt: - role: system content: You are a creative story writer. - role: user content: $ f'Write a short story about {steps[0].input.topic}'
Let’s create a simple AI agent that can help with writing tasks:
Copy
agent = client.agents.create( name="Writing Assistant", model="claude-3.5-sonnet", about="A helpful AI assistant that specializes in writing and editing.")
Let’s create a task that generates a short story based on a given topic:
Copy
import yaml task_definition = yaml.safe_load("""name: Story Generatordescription: Generate a short story based on a given topicmain:- prompt: - role: system content: You are a creative story writer. - role: user content: $ f'Write a short story about {steps[0].input.topic}'""")task = client.tasks.create( agent_id=agent.id, **task_definition # Unpack the task definition)
execution = client.executions.create( task_id=task.id, input={"topic": "a magical garden"})# Wait for the execution to completewhile (result := client.executions.get(execution.id)).status not in ['succeeded', 'failed']: print(result.status) time.sleep(1)if result.status == "succeeded": print(result.output)else: print(f"Error: {result.error}")