Skip to content

Commit 33747cb

Browse files
committed
Fix for spawn-agent-inline to match the version of the agent in spawnableAgents
1 parent 9262c1c commit 33747cb

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

backend/src/tools/handlers/tool/spawn-agent-inline.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,12 @@ import type { CodebuffToolCall } from '@codebuff/common/tools/list'
1010
import type { AgentTemplate } from '@codebuff/common/types/agent-template'
1111
import type { CodebuffMessage } from '@codebuff/common/types/message'
1212
import type { PrintModeEvent } from '@codebuff/common/types/print-mode'
13-
import type {
14-
AgentState,
15-
AgentTemplateType,
16-
} from '@codebuff/common/types/session-state'
13+
import type { AgentState } from '@codebuff/common/types/session-state'
1714
import type { ProjectFileContext } from '@codebuff/common/util/file'
1815
import type { WebSocket } from 'ws'
1916

17+
import { getMatchingSpawn } from './spawn-agents'
18+
2019
export const handleSpawnAgentInline = ((params: {
2120
previousToolCallFinished: Promise<void>
2221
toolCall: CodebuffToolCall<'spawn_agent_inline'>
@@ -91,16 +90,21 @@ export const handleSpawnAgentInline = ((params: {
9190
}
9291

9392
const triggerSpawnAgentInline = async () => {
94-
const agentType = agentTypeStr as AgentTemplateType
95-
const agentTemplate = await getAgentTemplate(agentType, localAgentTemplates)
96-
93+
const agentTemplate = await getAgentTemplate(
94+
agentTypeStr,
95+
localAgentTemplates,
96+
)
9797
if (!agentTemplate) {
9898
throw new Error(`Agent type ${agentTypeStr} not found.`)
9999
}
100100

101-
if (!parentAgentTemplate.spawnableAgents.includes(agentType)) {
101+
const agentType = getMatchingSpawn(
102+
parentAgentTemplate.spawnableAgents,
103+
agentTypeStr,
104+
)
105+
if (!agentType) {
102106
throw new Error(
103-
`Agent type ${parentAgentTemplate.id} is not allowed to spawn child agent type ${agentType}.`,
107+
`Agent type ${parentAgentTemplate.id} is not allowed to spawn child agent type ${agentTypeStr}.`,
104108
)
105109
}
106110

0 commit comments

Comments
 (0)