Spaces:
Sleeping
Sleeping
| import { resolveStudioToolChoice } from '../../session/session-agent-config' | |
| import { logPlotStudioSkillTrace } from '../../../observability/plot-studio-skill-trace' | |
| import { buildSubagentPrompt } from '../session-runner-helpers' | |
| import type { StudioSubagentRunRequest, StudioSubagentRunResult } from '../../tools/tool-runtime-context' | |
| import type { StudioSessionRunnerDependencies } from './dependency-center' | |
| export async function runSubagent( | |
| deps: Pick<StudioSessionRunnerDependencies, 'resolveSkill'>, | |
| input: StudioSubagentRunRequest, | |
| run: (input: { | |
| projectId: string | |
| session: StudioSubagentRunRequest['childSession'] | |
| inputText: string | |
| customApiConfig?: StudioSubagentRunRequest['customApiConfig'] | |
| toolChoice?: StudioSubagentRunRequest['toolChoice'] | |
| }) => Promise<{ text: string }>, | |
| ): Promise<StudioSubagentRunResult> { | |
| if (input.skillName) { | |
| logPlotStudioSkillTrace(input.childSession.studioKind, 'skill.subagent.requested', { | |
| parentSessionId: input.parentSession.id, | |
| childSessionId: input.childSession.id, | |
| subagentType: input.subagentType, | |
| requestedSkillName: input.skillName, | |
| files: input.files ?? [], | |
| }) | |
| } | |
| const skill = input.skillName && deps.resolveSkill | |
| ? await deps.resolveSkill(input.skillName, input.childSession) | |
| : undefined | |
| if (input.skillName) { | |
| logPlotStudioSkillTrace(input.childSession.studioKind, 'skill.subagent.resolved', { | |
| parentSessionId: input.parentSession.id, | |
| childSessionId: input.childSession.id, | |
| subagentType: input.subagentType, | |
| requestedSkillName: input.skillName, | |
| resolvedSkillName: skill?.name ?? null, | |
| resolvedEntryFile: skill?.entryFile ?? null, | |
| }, skill ? 'info' : 'warn') | |
| } | |
| const result = await run({ | |
| projectId: input.projectId, | |
| session: input.childSession, | |
| inputText: buildSubagentPrompt({ | |
| agentType: input.subagentType, | |
| inputText: input.inputText, | |
| skillName: input.skillName, | |
| skill, | |
| files: input.files, | |
| studioKind: input.childSession.studioKind | |
| }), | |
| customApiConfig: input.customApiConfig, | |
| toolChoice: input.toolChoice ?? resolveStudioToolChoice({ session: input.childSession }) | |
| }) | |
| return { | |
| text: result.text | |
| } | |
| } | |