Agent Class

The Agent class is the central component of the xpander SDK, representing an AI agent with capabilities for task execution, tool usage, and state management.

Retrieving an Agent

# Get an agent by ID
agent = client.agents.get(agent_id="agent-id-123")
ParameterTypeRequiredDescription
agent_idstringYesID of the agent

Returns: Agent instance

Agent Properties

Core Properties

PropertyTypeDescriptionAvailability
idstringUnique identifier for the agentAlways available
namestringName of the agentAlways available
instructionsobjectSystem instructions for the agentAlways available
metadataobjectContains metadata like descriptionAlways available
executionExecutionCurrent execution contextAfter adding a task
messagesList[Dict]Conversation messages arrayAfter initialization
graphGraphWorkflow graph systemAlways available
tool_choicestringSetting for tool selection behaviorAlways available

Configuration Properties

PropertyTypeDescription
memory_typeMemoryTypeType of memory (e.g., SHORT_TERM)
memory_strategyMemoryStrategyStrategy for memory management (e.g., FULL)
end_tool_enabledbooleanWhether automatic task ending is enabled
has_local_toolsbooleanWhether agent has local tools attached
access_scopeAgentAccessScopeAccess scope (e.g., ORGANIZATIONAL)
delegation_typeAgentDelegationTypeDelegation type (e.g., ROUTER)
knowledge_basesListConnected knowledge bases
organization_idstringID of the organization owning the agent

Agent Core Methods

update() / update()

Updates agent properties on the server.

# Update agent instructions
agent.instructions.general = "You are a helpful research assistant."
agent.instructions.goal = "Find accurate information."
agent.instructions.role = "Research, summarize, explain."

# Apply changes
agent.update()

Returns: Updated Agent object

sync() / sync()

Synchronizes changes to the agent (operations, graph connections, etc.)

# Synchronize agent
agent.sync()

Returns: Updated Agent object

disable_agent_end_tool() / disableAgentEndTool()

Disables the automatic task completion tool, giving more control over when a task ends.

# Disable automatic task completion
agent.disable_agent_end_tool()

Returns: void

update_user_details() / updateUserDetails()

Updates user details associated with the agent.

# Update user details
agent.update_user_details({
    "user_id": "user123",
    "name": "John Doe",
    "email": "john@example.com"
})
ParameterTypeRequiredDescription
user_detailsobjectYesUser information

Returns: void

retrieve_node_from_graph() / retrieveNodeFromGraph()

Retrieves a node from the agent’s graph by its ID.

# Get a node from the graph
node = agent.retrieve_node_from_graph("tool-id-123")
ParameterTypeRequiredDescription
item_idstringYesID of the graph node

Returns: GraphItem object or undefined if not found

Type Definitions

Instructions

interface Instructions {
  general: string;   // General instructions
  goal: string;      // Goal instructions
  role: string;      // Role instructions
}

Metadata

interface Metadata {
  description?: string;  // Agent description
  created_at: string;    // Creation timestamp
  updated_at: string;    // Last update timestamp
  llm_model?: string;    // Associated LLM model
}

UserDetails

interface UserDetails {
  userId: string;    // User ID
  name?: string;     // User name
  email?: string;    // User email
  role?: string;     // User role
}

Usage Example

from xpander_sdk import XpanderClient
import os

# Initialize client
client = XpanderClient(api_key=os.environ["XPANDER_API_KEY"])

# Get an agent
agent = client.agents.get(agent_id="agent-123")

# Update instructions
agent.instructions.general = "You are a research assistant."
agent.update()