Skip to main content
Your agent can work for the model that you already use in pi. You keep your usual model, for example a frontier model, as the main model of the pi session. A pi extension adds one tool that sends a question to your fine-tuned agent on Oumi. Your agent runs its own tool loop with the system prompt and tools from its training data, and returns its answer to the main model as the tool result. You do not switch models or sessions when work needs your agent. The main model makes one tool call, and your small fine-tuned model does the multi-step tool calling at a fraction of the cost and latency of a frontier model. This guide uses the same stock lookup agent as Run your agent as the main model. The agent has two tools: 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 pi agent loop sends your prompt to your main model, which calls ask_stock_agent. The subagent extension runs its own loop against your Oumi deployment, runs each stock tool against your data sources, and returns the answer to the pi agent loop The pi agent loop sends your prompt to your main model, which calls ask_stock_agent. The subagent extension runs its own loop against your Oumi deployment, runs each stock tool against your data sources, and returns the answer to the pi agent loop The two models do not see each other’s context:
  • 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.
Your fine-tuned model therefore gets the same context as in training, even though pi gives the main model coding tools and a coding system prompt.

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 ~/.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:
When you finish, the directory contains four files:
If you followed the main model guide, remove ~/.pi/agent/extensions/stock-tools.ts. Otherwise pi also gives the stock tools to the main model, and the main model can call them directly instead of asking your agent.
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 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
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.
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 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
The subagent reads your API key when the main model first calls 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_agent fails with 429 and “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_agent fails with 400 and “Invalid model format”: MODEL in agent.ts is not a model path. Set it to projects/{project_id}/deployments/{deployment_id}.
  • ask_stock_agent fails with ENOENT for api.key: The subagent cannot read your Oumi API key. Save the key in ~/.config/oumi/api.key.
  • ask_stock_agent does not appear in pi: pi did not load the extension. Make sure the file is named index.ts and 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_company or get_stock_price itself: 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_agent with reset set to true.

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.