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(llm_provider=LLMProvider.OPEN_AI)
ParameterTypeRequiredDescription
llm_providerLLMProvider enumNoFormat tools for a specific provider

Returns: Array of tool objects formatted for the specified LLM provider.

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"]
            }
        }
    ],
    llm_provider=LLMProvider.OPEN_AI
)

Parameters

ParameterTypeRequiredDescription
toolsarrayYesArray of tool definitions
llm_provider / llmProviderLLMProviderYesEnum value representing the LLM provider

Returns

Returns tools formatted for the specified LLM provider.

XpanderClient.extract_tool_calls() / extractToolCalls()

Static utility for extracting tool calls from LLM responses.

from xpander_sdk import XpanderClient, LLMProvider
from openai import OpenAI

# Initialize OpenAI client
openai_client = OpenAI(api_key="your-openai-api-key")

# Get a response from OpenAI with tool calls
response = openai_client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Search for information about AI safety"}],
    tools=[{
        "type": "function",
        "function": {
            "name": "web_search",
            "description": "Search the web for information",
            "parameters": {
                "type": "object",
                "properties": {
                    "query": {
                        "type": "string",
                        "description": "The search query"
                    }
                },
                "required": ["query"]
            }
        }
    }],
    tool_choice="auto"
)

# Extract tool calls
tool_calls = XpanderClient.extract_tool_calls(
    llm_response=response.model_dump(),
    llm_provider=LLMProvider.OPEN_AI
)

print(f"Extracted {len(tool_calls)} tool calls")
for tc in tool_calls:
    print(f"Tool: {tc.name}")
    print(f"Payload: {tc.payload}")
    print(f"Type: {tc.type}")
ParameterTypeRequiredDescription
llm_responseobjectYesRaw response from the LLM
llm_providerLLMProviderYesProvider that generated the LLM response

Returns: Array of ToolCall objects extracted from the LLM response.

Always use the same provider for extracting tool calls as you used for retrieving tools. The provider must match the LLM that generated the response.

XpanderClient.retrieve_pending_local_tool_calls() / retrievePendingLocalToolCalls()

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

local_tool_calls = XpanderClient.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

# Getting and executing tools
tools = agent.get_tools(llm_provider=LLMProvider.OPEN_AI)

# Extract tool calls from LLM response
tool_calls = XpanderClient.extract_tool_calls(
    llm_response=response,
    llm_provider=LLMProvider.OPEN_AI
)

# Execute the tools
results = agent.run_tools(tool_calls=tool_calls)

# Working with operations
interfaces = agent.retrieve_agentic_interfaces()
github_interface = next((i for i in interfaces if "github" in i.name.lower()), None)

if github_interface:
    operations = agent.retrieve_agentic_operations(agentic_interface=github_interface)
    agent.attach_operations(operations=[operations[0]])