import json
from stackone_ai import StackOneToolSet
from pydantic_ai import Agent, Tool
def create_agent_for_account(account_id: str):
# Initialize toolset and fetch tools
toolset = StackOneToolSet()
tools = toolset.fetch_tools(account_ids=[account_id])
# Convert each StackOne tool to a Pydantic AI Tool with proper schema
pydantic_tools = []
for stackone_tool in tools:
params_schema = stackone_tool.to_openai_function()["function"]["parameters"]
def execute(t=stackone_tool, **kwargs: object) -> str:
return json.dumps(t.execute(kwargs))
pydantic_tools.append(
Tool.from_schema(
execute,
name=stackone_tool.name,
description=stackone_tool.description,
json_schema=params_schema,
)
)
# Create agent with tools
agent = Agent(
"openai:gpt-5.4",
system_prompt="You are a helpful HR assistant.",
tools=pydantic_tools,
)
return agent
# Get account ID from your app's auth context or StackOne dashboard
account_id = "your-account-id"
agent = create_agent_for_account(account_id)
result = agent.run_sync("List the first 5 employees")
print(result.output)