Skip to main content

Environment Variable Support

The Backend module supports automatic agent ID detection from environment variables, eliminating the need to explicitly provide the agent ID in many scenarios.

Supported Environment Variables

  • XPANDER_AGENT_ID: The agent identifier that will be used when no agent_id or agent parameter is provided to the methods.

Environment Variable Usage

Note: If both an environment variable and explicit parameters are provided, the explicit parameters take precedence.

Introduction

The Backend Module provides comprehensive functionality for retrieving agent runtime arguments for execution within the xpander.ai platform. This module supports multiple AI frameworks and dispatches agent arguments accordingly.

Overview

In this module, you can:
  • Resolve runtime arguments for agents with framework-specific configurations
  • Support multiple AI frameworks through intelligent dispatching
  • Handle both asynchronous and synchronous argument resolution
  • Override default configurations with custom parameters
  • Integrate with tasks for context-aware argument generation
  • Monitor task execution in real-time with event callbacks

Examples

Basic Agent Arguments Resolution

This example demonstrates how to resolve runtime arguments for an agent in both asynchronous and synchronous styles.

Asynchronous Example

Synchronous Example

Using Pre-loaded Agent Instance

When you already have an Agent instance, you can use it directly for more efficient argument resolution.

Asynchronous Example

Synchronous Example

Task Context Integration

Include task context for runtime-aware argument resolution.

Asynchronous Example

Synchronous Example

Custom Overrides

Override default configurations with custom parameters.

Asynchronous Example

Synchronous Example

Authentication Events Callback

Handle authentication events in real-time by providing an event callback function. This callback is triggered only for authentication flows (e.g., MCP OAuth requiring user login). You can use both approaches simultaneously - decorated handlers are auto-registered and always invoked, and you can also pass an explicit callback for additional per-call handling.

Option 1: Direct Callback (Per-call)

Option 2: Decorator (Auto-registered)

Option 3: Combine Both

Callback Parameters:
  • agent: The Agent object associated with the task
  • task: The Task object being executed
  • event: A TaskUpdateEvent containing:
    • type: Event type (always “auth_event” for authentication flows)
    • time: Timestamp of the event
    • data: Authentication-specific data (e.g., OAuth login URL, token status)

Framework-Specific Usage

The Backend module automatically detects the agent’s framework and provides appropriate arguments.

Agno Framework Example


Continue to the [Backend API Reference] for detailed documentation on classes and methods.

Agents Module

Agent management and interaction

Tasks Module

Task execution and management

Configuration

SDK configuration and authentication

Types

Data types and models

Support

For additional help: