from stackone_ai import StackOneToolSet
from pydantic_ai import Agent
from pydantic_ai.models.openai import OpenAIModel
def create_agent_for_account(account_id: str):
"""
Create agent with tools for a specific account.
In production, account_id comes from:
- User/tenant context
- Authentication middleware
- Database lookup
"""
# Initialize toolset
toolset = StackOneToolSet()
# Fetch tools dynamically for this account
tools = toolset.fetch_tools(account_ids=[account_id])
# Create Pydantic AI agent
agent = Agent(
model=OpenAIModel('gpt-5'),
system_prompt="You are a helpful HR assistant with access to employee data."
)
# Register StackOne tools
openai_tools = tools.to_openai()
for tool_def in openai_tools:
tool_name = tool_def['function']['name']
tool = tools.get_tool(tool_name)
# Create callable function
def make_tool_func(t=tool):
def tool_func(**kwargs):
result = t.call(**kwargs)
return result.data if hasattr(result, 'data') else result
return tool_func
agent.tool(make_tool_func(), name=tool_name)
return agent
# Use the agent
account_id = get_current_user_account() # Your function
agent = create_agent_for_account(account_id)
result = agent.run_sync("List employees in engineering department")
print(result.data)