xpander Open Source SDK is designed to empower developers to build intelligent and reliable AI Agents capable of managing complex, multi-step tasks across diverse systems and platforms without focusing on function calling, schema definition, graph enforcement, and prompt group management.
This documentation provides a comprehensive guide to all the classes, methods, and constants available in the xpander SDK.
With support for leading LLM providers such as OpenAI, Amazon Bedrock, and NVIDIA NIM, the xpander SDK seamlessly integrates into your existing systems, simplifying function calling, agent orchestration, and tool management.
Installing the SDK
Get the Agent Key and Agent ID
Go to https://app.xpander.ai/workbench, click on add new Source Node and select the SDK source.
Initializing the SDK
The library runs as a NodeJS app under the hood and is compiled safely using
Projen. In order to run our SDK smoothly, you must have
NodeJS installed.
Hello world example
from xpander_sdk import XpanderClient, LLMProvider
from openai import OpenAI
from dotenv import load_dotenv
import os
load_dotenv()
OpenAPIKey = os.environ.get("OPENAI_API_KEY","")
xpanderAPIKey = os.environ.get("XPANDER_API_KEY","")
xpanderAgentURL = os.environ.get("XPANDER_AGENT_URL","")
openai_client = OpenAI(api_key=OpenAPIKey)
xpander_client = XpanderClient(
agent_key=xpanderAPIKey,
agent_url=xpanderAgentURL,
llm_provider=LLMProvider.OPEN_AI
)
xpander_client.start_session(prompt="Events managements")
memory = []
memory.append({"role": "system", "content": "You are a helpful assistant, you are running in While loop and will have access to invoke tools dynmaically to your location in the graph. If you want to stop the loop, please add ##FINAL ANSWER## in your answer"})
memory.append({"role": "user", "content": "Get events and send it to David on Slack"})
number_of_calls = 1
while True:
llm_response = openai_client.chat.completions.create(
model="gpt-4o",
messages=memory,
tools=xpander_client.tools(),
tool_choice="auto",
max_tokens=1024,
)
memory.append({"role": "assistant", "content": f'Step number: {number_of_calls}'})
memory.append(llm_response.choices[0].message)
if(llm_response.choices[0].message.tool_calls):
tool_response = xpander_client.xpander_tool_call(tool_selector_response=llm_response.model_dump())
for tool_response in tool_response:
memory.append({"role": "tool", "content": tool_response.response_message, "tool_call_id": tool_response.tool_call_id})
if (llm_response.choices[0].message.content):
if "##FINAL ANSWER##" in llm_response.choices[0].message.content:
break
number_of_calls += 1
print(llm_response.choices[0].message.content)