from julep import Julep
import yaml
import time
# Initialize the Julep client
julep = Julep(api_key="your_api_key")
# Create an agent
agent = julep.agents.create(
name="Task Agent",
model="gpt-4o"
)
task_def = yaml.safe_load("""
# yaml-language-server: $schema=https://raw.githubusercontent.com/julep-ai/julep/refs/heads/dev/src/schemas/create_task_request.json
name: Julep Trip Planning Task
description: A Julep agent that can generate a detailed itinerary for visiting tourist attractions in some locations, considering the current weather conditions.
input_schema:
type: object
properties:
locations:
type: array
items:
type: string
description: The locations to search for.
tools:
- name: wikipedia
type: integration
integration:
provider: wikipedia
- name: weather
type: integration
integration:
provider: weather
setup:
openweathermap_api_key: "YOUR_OPENWEATHERMAP_API_KEY"
- name: internet_search
type: integration
integration:
provider: brave
setup:
brave_api_key: "YOUR_BRAVE_API_KEY"
main:
- over: $ steps[0].input.locations
map:
tool: weather
arguments:
location: $ _
- over: $ steps[0].input.locations
map:
tool: internet_search
arguments:
query: $ 'tourist attractions in ' + _
# Zip locations, weather, and attractions into a list of tuples [(location, weather, attractions)]
- evaluate:
zipped: |-
$ list(
zip(
steps[0].input.locations,
[output['result'] for output in steps[0].output],
steps[1].output
)
)
- over: $ _['zipped']
parallelism: 3
# Inside the map step, each `_` represents the current element in the list
# which is a tuple of (location, weather, attractions)
map:
prompt:
- role: system
content: >-
$ f'''You are {agent.name}. Your task is to create a detailed itinerary
for visiting tourist attractions in some locations.
The user will give you the following information for each location:
- The location
- The current weather condition
- The top tourist attractions'''
- role: user
content: >-
$ f'''Location: "{_[0]}"
Weather: "{_[1]}"
Attractions: "{_[2]}"'''
unwrap: true
- evaluate:
final_plan: |-
$ '\\n---------------\\n'.join(activity for activity in _)
""")
# Create a task
task = julep.tasks.create(
agent_id=agent.id,
**task_def
)
# Execute the task with specific input that matches the task's input schema
execution = julep.tasks.execute(
task_id=task.id,
input={"locations": ["New York", "Paris", "Tokyo"]}
)
# Fetch the execution status & current output
execution = julep.executions.get(execution_id=execution.id)
while execution.status not in ["succeeded", "failed", "cancelled"]:
execution = julep.executions.get(execution_id=execution.id)
print(f"Execution status: {execution.status}")
print(f"Execution output: {execution.output}")
print("************************************************")
# Wait for 5 seconds before polling again
time.sleep(5)