search_company finds the ticker symbol for a company name, and get_stock_price returns the latest price for a ticker. The main model gets one tool, ask_stock_agent.
HOW THE PIECES CONNECT
- The main model sees pi’s system prompt, its own tools, and
ask_stock_agent. It does not see the stock tools or your agent’s system prompt. - Your fine-tuned model sees only the requests that the subagent sends: the system prompt from your training data, the stock tools, and the subagent’s own history. It does not see pi’s prompt, pi’s tools, or your conversation with the main model.
BEFORE YOU START
You will need:- An Oumi project.
- pi, installed on your machine by following the pi quickstart instructions, with a main model that you already use.
- A personal Oumi API key from User Settings > API Keys.
- The system prompt from your agent’s training data.
1
Train and deploy a tool-calling model
Follow the first two steps of Run your agent as the main model: train a tool-calling model, deploy it, and save your Oumi API key in
~/.config/oumi/api.key. Copy the model path of the deployment, for example projects/{project_id}/deployments/{deployment_id}.2
Create the extension directory
pi loads a subdirectory of When you finish, the directory contains four files:
~/.pi/agent/extensions/ that contains an index.ts file as one extension. Create the directory, and save the system prompt from your training data in it:3
Define and implement the tools
pi does not run your agent’s tools in this setup. The subagent sends the tool definitions with each request to your deployment, and runs each tool call itself.Write each definition in the OpenAI tools format from its Oumi tool. Copy the Oumi A tool that finds no match returns a result that says so. A tool whose data source fails throws an error, and the subagent sends that error to the model as the tool result. Neither path invents a value.
toolName into name, and copy description and parameters without changes. The model learned your tools from these definitions.Create ~/.pi/agent/extensions/stock-agent/tools.ts:tools.ts
4
Write the subagent's tool loop
The subagent does for your fine-tuned model what pi does for a main model. It sends the conversation and the tool definitions to your deployment, runs each tool call in the reply, adds the results to the conversation, and repeats until the model answers without a tool call.Create
~/.pi/agent/extensions/stock-agent/agent.ts, and set MODEL to the model path of your deployment:agent.ts
5
Give the main model the subagent as a tool
The main model decides when to call The subagent reads your API key when the main model first calls
ask_stock_agent from the tool’s description alone. Say what your agent can answer and what it remembers, so that the main model calls it for the right questions.Create ~/.pi/agent/extensions/stock-agent/index.ts:index.ts
ask_stock_agent, so a pi session that never asks your agent does not need the key.6
Ask a question in pi
Start pi as you usually do, with your usual model. If pi is already running, run
/reload. Then ask a question such as “Is Nucor trading above 150 today?”.The main model calls ask_stock_agent. While your agent works, pi shows each of its tool calls under the ask_stock_agent call: search_company to find the ticker NUE, then get_stock_price with that ticker. The main model then answers you from your agent’s reply.Ask a follow-up such as “And how about Apple?”. The main model calls ask_stock_agent again, and your agent answers with the conversation from the first question still in its history.TROUBLESHOOTING
ask_stock_agentfails with429and “Deployment is warming up”: Your deployment uses scale-to-zero and has no warm replica. The subagent does not wait for a cold start. Wait a few minutes and ask again, or set min replicas to 1.ask_stock_agentfails with400and “Invalid model format”:MODELinagent.tsis not a model path. Set it toprojects/{project_id}/deployments/{deployment_id}.ask_stock_agentfails withENOENTforapi.key: The subagent cannot read your Oumi API key. Save the key in~/.config/oumi/api.key.ask_stock_agentdoes not appear in pi: pi did not load the extension. Make sure the file is namedindex.tsand is in~/.pi/agent/extensions/stock-agent/, then run/reload.- The main model answers stock questions without calling
ask_stock_agent: The main model does not know when to call your agent. Make the tool’s description more specific about the questions that your agent answers, then run/reload. - The main model calls
search_companyorget_stock_priceitself: pi also loads the stock tools from another extension. Remove~/.pi/agent/extensions/stock-tools.ts. - Your agent answers from an earlier, unrelated conversation: The subagent keeps its history for the whole pi session. Ask the main model to reset the stock agent, so that it calls
ask_stock_agentwithresetset totrue.
WHAT’S NEXT
Run your agent as the main model
Select your fine-tuned model in pi and give it only your tools.
Inference logs
Review the requests that the subagent sent to your deployment.
Compounding intelligence
Find where your deployed model struggles, and retrain it on targeted data.
Agent harnesses
Learn what an agent harness contains, including subagents.