The Backend module supports automatic agent ID detection from environment variables, eliminating the need to explicitly provide the agent ID in many scenarios.
import osfrom xpander_sdk import Backend# Set the environment variableos.environ["XPANDER_AGENT_ID"] = "agent-123"backend = Backend()# No need to specify agent_id - it will be auto-detectedargs = await backend.aget_args()print(f"Arguments resolved for agent: {args}")
Note: If both an environment variable and explicit parameters are provided, the explicit parameters take precedence.
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.
from xpander_sdk import Backendbackend = Backend()# Resolve arguments by agent IDargs = await backend.aget_args(agent_id="agent-123")print(f"Resolved arguments: {args}")# Use resolved arguments with your framework# For example, with Agno framework:from agno import Agent as AgnoAgentagent = AgnoAgent(**args)
from xpander_sdk import Backendbackend = Backend()# Resolve arguments by agent IDargs = backend.get_args(agent_id="agent-123")print(f"Resolved arguments: {args}")# Use resolved arguments with your frameworkfrom agno import Agent as AgnoAgentagent = AgnoAgent(**args)
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.
from xpander_sdk import Backend, on_auth_event# Global handler for all auth events@on_auth_eventasync def log_all_auth(agent, task, event): print(f"[GLOBAL] Auth event")# Additional one-time handlerasync def custom_handler(agent, task, event): print(f"[CUSTOM] Specific handling")# Both handlers will be invokedargs = await backend.aget_args( agent_id="agent-123", auth_events_callback=custom_handler)
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)
from xpander_sdk import Backendfrom agno import Agent as AgnoAgentbackend = Backend()# Resolve arguments for Agno framework agentargs = await backend.aget_args(agent_id="agno-agent-123")# Create Agno agent with resolved argumentsagno_agent = AgnoAgent(**args)# Run the agentresponse = agno_agent.run("What's the weather like today?")print(response.content)
Continue to the [Backend API Reference] for detailed documentation on classes and methods.