Overview

The Tourist Plan task demonstrates how to:

  • Execute Julep workflow-steps in parallel
  • Integrate with external APIs (Weather and Brave Search)
  • Combine data from multiple sources
  • Generate personalized itineraries using AI

Task Structure

Let’s break down the task into its core components:

1. Input Schema

First, we define what inputs our task expects:


input_schema:
    type: object
    properties:
        locations:
            type: array
            items:
                type: string

This schema specifies that our task expects an array of location strings (e.g., ["New York", "London", "Paris"]).

2. Tools Configuration

Next, we define the external tools our task will use:

- name: weather
  type: integration
  integration:
    provider: weather
    setup:
      openweathermap_api_key: YOUR_OPENWEATHERMAP_API_KEY

- name: internet_search
  type: integration
  integration:
    provider: brave
    setup:
      api_key: YOUR_BRAVE_API_KEY

We’re using two integrations:

  • The weather integration to fetch current weather conditions
  • The brave search integration to find tourist attractions

3. Main Workflow Steps

1

Get Weather Data

- over: $ steps[0].input.locations
map:
  tool: weather
  arguments:
    location: $ _

This step:

  • Iterates over each location in the input array
  • Calls the weather API for each location
2

Search for Tourist Attractions

- over: $ steps[0].input.locations
map:
  tool: internet_search
  arguments:
    query: $ 'tourist attractions in ' + _

This step:

  • Iterates over the locations again
  • Searches for tourist attractions in each location
  • Constructs a search query by concatenating “tourist attractions in ” with the location
3

Combine Data

- evaluate:
  zipped: |-
    $ list(
      zip(
        steps[0].input.locations,
        [output['result'] for output in steps[0].output],
        steps[1].output
      )
    )

This step:

  • Combines the data from previous steps into tuples
  • Each tuple contains: (location, weather_data, attractions_data)
  • Uses Python’s zip function to align the data
4

Generate Itineraries

- 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

This step:

  • Processes up to 3 locations in parallel
  • For each location tuple:
    • Sends a prompt to the AI model
    • Includes location, weather, and attraction data
    • Generates a personalized itinerary
5

Format Final Output

- evaluate:
  final_plan: |-
    $ '\\n---------------\\n'.join(activity for activity in _)

This step:

  • Combines all itineraries into a single output
  • Separates each itinerary with a divider

Usage

Here’s how to use this task with the Julep SDK:

from julep import Client
import time
import yaml

# Initialize the client
client = Client(api_key=JULEP_API_KEY)

# Load the task definition
with open('trip_planning_task.yaml', 'r') as file:
  task_definition = yaml.safe_load(file)

# Create the task
task = client.tasks.create(
  agent_id=AGENT_ID,
  **task_definition
)

# Create the execution
execution = client.executions.create(
    task_id=task.id,
    input={
        "locations": ["New York", "London", "Paris", "Tokyo", "Sydney"]
    }
)

# Wait for the execution to complete
while (result := client.executions.get(execution.id)).status not in ['succeeded', 'failed']:
    print(result.status)
    time.sleep(1)

# Print the result
if result.status == "succeeded":
    print(result.output)
else:
    print(f"Error: {result.error}")

Example Output

An example output when running this task with an input of ["New York", "London", "Paris", "Tokyo", "Sydney"]:

Next Steps

Try this task yourself, check out the full example, see the trip-planning cookbook.