Agentic Behavior

What makes an agent an agent is the ability to chain multiple tool calls to solve more complex problems.

Multi-Step Reasoning

// Tools that work together
final tools = [
  Tool(
    name: 'get_current_time',
    description: 'Get the current date and time',
    onCall: (_) async => {'time': '2025-01-27T10:00:00Z'},
  ),
  Tool(
    name: 'find_events',
    description: 'Find events for a date',
    inputSchema: JsonSchema.object({
      'date': JsonSchema.string(),
    }),
    onCall: (args) async => {
      'events': ['Team Meeting at 11am', 'Lunch at 12pm'],
    },
  ),
];

// Agent chains tools automatically
final agent = Agent('openai', tools: tools);
final result = await agent.send(
  'What events do I have today? Find the current date first.'
);

// Agent will:
// 1. Call get_current_time → gets "2025-01-27"
// 2. Extract date from response
// 3. Call find_events with that date
// 4. Return final answer with events

Complex Workflows

// Weather + activity planning
final tools = [
  weatherTool,    // Gets weather
  activityTool,   // Suggests activities based on weather
  bookingTool,    // Books the activity
];

final result = await agent.send(
  'Plan an outdoor activity for tomorrow in Seattle'
);
// Agent chains: weather → activity → booking

Loop Behavior

Agents continue until task completion:

  • Call tools as needed
  • Use output from one as input to another
  • Stop when answer is complete

Next Steps