Skip to main content
Build sophisticated AI agents using LangChain’s framework with seamless access to business data through StackOne’s unified API.

Overview

  • ReAct and OpenAI Functions agents with business tool access
  • Multi-step workflow automation
  • Conversational agents with memory
  • Advanced error handling and resilience
from stackone_ai import StackOneToolSet
from langchain_openai import ChatOpenAI

def create_agent_for_account(account_id: str):
    """
    Create LangChain agent with tools for a specific account.

    In production, account_id comes from:
    - User/tenant context
    - Authentication middleware
    - Request parameters
    """
    # Initialize toolset
    toolset = StackOneToolSet()

    # Fetch tools dynamically for this account
    tools = toolset.fetch_tools(account_ids=[account_id])
    langchain_tools = tools.to_langchain()

    # Create model with tools
    model = ChatOpenAI(model="gpt-5-mini")
    model_with_tools = model.bind_tools(langchain_tools)

    return model_with_tools, tools

# Usage: Get account from user context
account_id = get_current_user_account()  # Your function
model, tools = create_agent_for_account(account_id)

# Use the agent
response = model.invoke("List all employees in engineering")

# Handle tool execution
for tool_call in response.tool_calls:
    tool = tools.get_tool(tool_call["name"])
    if tool:
        result = tool.execute(tool_call["args"])
        print(f"Result: {result}")