Let’s explore a practical example of an agent that needs to follow a specific workflow:
Users might ask the agent to research a specific topic, and the agent should follow this sequence:
First, search for general information about the topic
Once basic information is found, extract specific details
Finally, analyze or summarize the collected information
Without AGS constraints, the agent might skip steps or perform them in an incorrect order, leading to incomplete or inaccurate results.
With AGS we can design a graph that enforces the correct sequence of operations without limiting the agent’s ability to make decisions.
This example shows how AGS enforces the correct sequence of operations, ensuring data is gathered methodically and reliably.
Bounded autonomy: Agents make decisions within your constraints
Logical gatekeeping: Ensures prerequisites are met before advancing
Reduced hallucinations: Prevents agents from making up data they should retrieve
Workflow optimization: Creates efficient paths for multi-step tasks
Simplified maintenance: Easier to update agent behavior by modifying the graph
You can create agent graphs using either the visual UI or programmatically with the SDK. Both approaches offer the same functionality, with the visual builder being more intuitive for non-developers and the SDK providing more flexibility for programmers.
The xpander.ai UI provides a drag-and-drop interface for creating agent graphs:
1
Access the Graph Builder
Navigate to your agent in the xpander.ai dashboard and select the “Graph” tab
2
Add Operations
Drag operations from the sidebar into your graph workspace
3
Create Connections
Draw lines between operations to establish dependencies
4
Test Your Graph
Use the interface options to test your agent with different invocation methods
5
Deploy
Save changes to deploy your updated graph
The visual builder gives you all the power of AGS without writing code, making it accessible to both developers and non-developers.
A well-structured agent graph typically demonstrates:
Top Level: Operations that run first (initial searches, data gathering)
Middle Level: Operations that depend on top-level results
Bottom Level: Operations that require specific data from previous steps
The SDK offers a programmatic approach that provides the same capabilities as the visual builder, but with the flexibility to create and modify graphs through code:
1
Add Operations to Your Agent
# Attach operations to your agentagent.attach_operations(operations=[operation1, operation2])
This example shows how to initialize a basic agent for a meeting recording application:
from xpander_sdk import XpanderClient, LLMProvider, Tokens, LLMTokensfrom openai import OpenAIimport datetimeimport timeclass MeetingAgent: def __init__(self, openai_api_key, xpander_api_key, agent_id): self.agent_id = agent_id self.xpander_client = XpanderClient(api_key=xpander_api_key) self.openai_client = OpenAI(api_key=openai_api_key) self.agent = self.xpander_client.agents.get(agent_id=self.agent_id) def run(self, prompt=None, thread_id=None): """Run the agent with the given prompt""" # Create task with thread management self.agent.add_task( input=prompt or "Check the status of all recorded meetings.", thread_id=thread_id if thread_id else None ) # Run the agent execution loop while not self.agent.is_finished(): response = self.openai_client.chat.completions.create( model="gpt-4o", messages=self.agent.messages, tools=self.agent.get_tools(llm_provider=LLMProvider.OPEN_AI), tool_choice=self.agent.tool_choice, temperature=0.0 ) self.agent.add_messages(response.model_dump()) tool_calls = XpanderClient.extract_tool_calls( llm_response=response.model_dump(), llm_provider=LLMProvider.OPEN_AI ) if tool_calls: self.agent.run_tools(tool_calls=tool_calls) # Process results result = self.agent.retrieve_execution_result() return result.result, result.memory_thread_id