Tool Methods

Methods for discovering, executing, and managing tools in the xpander SDK.

get_tools() / getTools()

Returns available tools, optionally formatted for a specific LLM provider.

tools = agent.get_tools()
ParameterTypeRequiredDescription

Different LLM providers require specific tool formats. Always specify the appropriate provider:

  • LLMProvider.OPEN_AI: For OpenAI models (GPT-3.5, GPT-4, GPT-4o)
  • LLMProvider.ANTHROPIC: For Anthropic Claude models directly
  • LLMProvider.GENERIC: Generic provider format
  • LLMProvider.BEDROCK_CLAUDE: Amazon Bedrock Claude models
  • LLMProvider.VERTEX_AI: Google Vertex AI models
  • LLMProvider.FRIENDLI_AI: For Claude models via FriendliAI API
  • LLMProvider.GEMINI_OPEN_AI: For Google Gemini with OpenAI format

run_tool() / runTool()

Executes a single tool by name with specified input parameters.

result = agent.run_tool(
    tool_name="web_search",
    tool_input={"query": "latest AI advancements"}
)
ParameterTypeRequiredDescription
tool_namestringYesName of the tool to execute
tool_inputobjectYesInput parameters for the tool

Returns: ToolCallResult object containing the execution result.

run_tools() / runTools()

Executes multiple tool calls extracted from an LLM response.

results = agent.run_tools(tool_calls=tool_calls)
ParameterTypeRequiredDescription
tool_callsarray of ToolCallYesArray of tool calls to execute

Returns: Array of ToolCallResult objects containing execution results.

add_tool_call_results() / addToolCallResults()

Adds tool execution results to the agent’s message history as tool messages.

from xpander_sdk import ToolCallResult

tool_results = [
    ToolCallResult(
        function_name="get_weather",
        tool_call_id="call-123",
        is_success=True,
        result="The weather in New York is sunny with a temperature of 72°F.",
        payload={"location": "New York"}
    )
]

agent.add_tool_call_results(tool_call_results=tool_results)
ParameterTypeRequiredDescription
tool_call_resultsList[ToolCallResult]YesArray of tool results

Returns: void

This method is primarily needed for local tools whose results aren’t automatically reported to the platform. Cloud-based tools managed by the xpander.ai platform automatically add their results to the message history.

add_local_tools() / addLocalTools()

Adds custom, locally-implemented tools to the agent.

agent.add_local_tools([{
    "name": "tool_name",
    "description": "Tool description",
    "function": function_reference,
    "parameters": {
        "type": "object",
        "properties": {
            "param1": {
                "type": "string",
                "description": "Parameter description"
            }
        },
        "required": ["param1"]
    }
}])
ParameterTypeRequiredDescription
toolsarray of objectsYesArray of tool definitions to add

Returns: void

Tool Definition Object Properties

PropertyTypeRequiredDescription
namestringYesUnique name for the tool
descriptionstringYesDescription of what the tool does
functionfunctionYesReference to implementation function
parametersobjectYesJSON Schema of function parameters

Static Utility Methods

XpanderClient.format_tools() / formatTools()

Static utility method to format tools for various LLM providers.

from xpander_sdk import XpanderClient, LLMProvider

tools_formatted = XpanderClient.format_tools(
    tools=[
        {
            "name": "search",
            "description": "Search for information",
            "parameters": {
                "type": "object",
                "properties": {
                    "query": {
                        "type": "string",
                        "description": "The search query"
                    }
                },
                "required": ["query"]
            }
        }
    ],
)

Parameters

ParameterTypeRequiredDescription
toolsarrayYesArray of tool definitions

Returns tools formatted for the specified LLM provider.

agent.extract_tool_calls() / extractToolCalls()

Extracts tool calls from an LLM response using the agent’s selected provider.

response = openai_client.chat.completions.create(
    model="gpt-4.1",
    messages=agent.messages,
)
tool_calls = agent.extract_tool_calls(llm_response=response.model_dump())
ParameterTypeRequiredDescription
llm_responseobjectYesRaw response from the LLM
llm_provider / llmProviderLLMProviderNoProvider used to parse the response

The agent automatically uses its configured LLM provider when llm_provider is omitted. Change it with agent.select_llm_provider() if you need to parse a response from another provider. You can also call XpanderClient.extract_tool_calls() directly when working without an agent.

agent.retrieve_pending_local_tool_calls() / retrievePendingLocalToolCalls()

Filters tool calls to retrieve only those that should be processed locally.

local_tool_calls = agent.retrieve_pending_local_tool_calls(
    tool_calls=tool_calls
)
ParameterTypeRequiredDescription
tool_callsarray of ToolCallYesArray of tool calls to filter

Returns: Array of ToolCall objects that should be processed locally.

Agentic Interface Methods

retrieve_agentic_interfaces() / retrieveAgenticInterfaces()

Returns available connector interfaces that provide pre-built operations.

interfaces = agent.retrieve_agentic_interfaces()

Returns: Array of AgenticInterface objects representing available connectors.

retrieve_agentic_operations() / retrieveAgenticOperations()

Retrieves available operations from a specific interface.

operations = agent.retrieve_agentic_operations(agentic_interface=interface)
ParameterTypeRequiredDescription
agentic_interfaceAgenticInterfaceYesThe interface to get operations from

Returns: Array of Operation objects available from the specified interface.

attach_operations() / attachOperations()

Attaches operations to the agent so they become available as tools.

agent.attach_operations(operations=[operation1, operation2])
ParameterTypeRequiredDescription
operationsarray of OperationYesArray of operations to attach

Returns: void

Type Definitions

ToolCall

Represents a tool call extracted from an LLM response.

interface ToolCall {
  id: string;
  name: string;
  type: ToolCallType;
  payload: any;
  graphApproved: boolean;
}

ToolCallResult

Represents the result of executing a tool call.

interface ToolCallResult {
  toolCallId: string;
  functionName: string;
  isSuccess: boolean;
  result: string;
  payload: any;
  graphApproved: boolean;
}

AgenticInterface

Represents a connector interface that provides operations.

interface AgenticInterface {
  id: string;
  name: string;
  description: string;
  iconUrl: string;
}

Operation

Represents a pre-built operation from an interface.

interface Operation {
  id: string;
  name: string;
  description: string;
  interface: AgenticInterface;
  parameters: object;
}

Usage Example

# Extract tool calls and execute them
tool_calls = agent.extract_tool_calls(llm_response=response)
results = agent.run_tools(tool_calls=tool_calls)

For more examples of tool definitions and usage, see the xpander-sdk tool docs.