fix(coding-agent): inherit subagent session config (#7897)

This commit is contained in:
Dustin Spicuzza 2026-08-11 05:12:34 -04:00 • committed by GitHub
parent 06ed871679
commit e3798ca91f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 23 additions and 3 deletions

View file

@ -137,6 +137,8 @@ model: claude-haiku-4-5
System prompt for the agent goes here.
```
When `model` is omitted, the subagent inherits the dispatching session's active model and thinking level.
**Locations:**
- `~/.pi/agent/agents/*.md` - User-level (always loaded)
- `.pi/agents/*.md` - Project-level (only with `agentScope: "project"` or `"both"`)

View file

@ -16,7 +16,7 @@ import { spawn } from "node:child_process";
import * as fs from "node:fs";
import * as os from "node:os";
import * as path from "node:path";
import type { AgentToolResult } from "@earendil-works/pi-agent-core";
import type { AgentToolResult, ThinkingLevel } from "@earendil-works/pi-agent-core";
import type { Message } from "@earendil-works/pi-ai";
import { StringEnum } from "@earendil-works/pi-ai";
import {
@ -264,8 +264,14 @@ function getPiInvocation(args: string[]): { command: string; args: string[] } {
type OnUpdateCallback = (partial: AgentToolResult<SubagentDetails>) => void;
interface DispatchDefaults {
model?: string;
thinkingLevel?: ThinkingLevel;
}
async function runSingleAgent(
defaultCwd: string,
dispatchDefaults: DispatchDefaults,
agents: AgentConfig[],
agentName: string,
task: string,
@ -292,7 +298,12 @@ async function runSingleAgent(
}
const args: string[] = ["--mode", "json", "-p", "--no-session"];
if (agent.model) args.push("--model", agent.model);
const inheritsDispatchConfig = !agent.model;
const model = agent.model ?? dispatchDefaults.model;
if (model) args.push("--model", model);
if (inheritsDispatchConfig && dispatchDefaults.thinkingLevel) {
args.push("--thinking", dispatchDefaults.thinkingLevel);
}
if (agent.tools && agent.tools.length > 0) args.push("--tools", agent.tools.join(","));
let tmpPromptDir: string | null = null;
@ -306,7 +317,7 @@ async function runSingleAgent(
messages: [],
stderr: "",
usage: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, cost: 0, contextTokens: 0, turns: 0 },
model: agent.model,
model,
step,
};
@ -471,6 +482,10 @@ export default function (pi: ExtensionAPI) {
async execute(_toolCallId, params, signal, onUpdate, ctx) {
const agentScope: AgentScope = params.agentScope ?? "user";
const dispatchDefaults: DispatchDefaults = {
model: ctx.model ? `${ctx.model.provider}/${ctx.model.id}` : undefined,
thinkingLevel: ctx.thinkingLevel,
};
const discovery = discoverAgents(ctx.cwd, agentScope);
const agents = discovery.agents;
const confirmProjectAgents = params.confirmProjectAgents ?? true;
@ -552,6 +567,7 @@ export default function (pi: ExtensionAPI) {
const result = await runSingleAgent(
ctx.cwd,
dispatchDefaults,
agents,
step.agent,
taskWithContext,
@ -624,6 +640,7 @@ export default function (pi: ExtensionAPI) {
const results = await mapWithConcurrencyLimit(params.tasks, MAX_CONCURRENCY, async (t, index) => {
const result = await runSingleAgent(
ctx.cwd,
dispatchDefaults,
agents,
t.agent,
t.task,
@ -666,6 +683,7 @@ export default function (pi: ExtensionAPI) {
if (params.agent && params.task) {
const result = await runSingleAgent(
ctx.cwd,
dispatchDefaults,
agents,
params.agent,
params.task,