Skip to content

Commit d9eb2be

Browse files
committed
lookup_agent_info tool
1 parent 580a4e5 commit d9eb2be

File tree

13 files changed

+173
-10
lines changed

13 files changed

+173
-10
lines changed

.agents/factory/base.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export const base = (
3838
'run_terminal_command',
3939
'str_replace',
4040
'write_file',
41+
'lookup_agent_info',
4142
'spawn_agents',
4243
'spawn_agent_inline',
4344
'add_subgoal',

.agents/types/agent-definition.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
* export default definition
1515
*/
1616

17-
import type { Message, ToolResultOutput, JsonObjectSchema } from './util-types'
1817
import type * as Tools from './tools'
18+
import type { Message, ToolResultOutput, JsonObjectSchema } from './util-types'
1919
type ToolName = Tools.ToolName
2020

2121
// ============================================================================
@@ -196,6 +196,7 @@ export interface AgentDefinition {
196196

197197
export interface AgentState {
198198
agentId: string
199+
runId: string
199200
parentId: string | undefined
200201

201202
/** The agent's conversation history: messages from the user and the assistant. */

.agents/types/tools.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import type { Message } from './util-types'
2-
31
/**
42
* Union type of all available tool names
53
*/
@@ -8,6 +6,7 @@ export type ToolName =
86
| 'code_search'
97
| 'end_turn'
108
| 'find_files'
9+
| 'lookup_agent_info'
1110
| 'read_docs'
1211
| 'read_files'
1312
| 'run_file_change_hooks'
@@ -28,6 +27,7 @@ export interface ToolParamsMap {
2827
code_search: CodeSearchParams
2928
end_turn: EndTurnParams
3029
find_files: FindFilesParams
30+
lookup_agent_info: LookupAgentInfoParams
3131
read_docs: ReadDocsParams
3232
read_files: ReadFilesParams
3333
run_file_change_hooks: RunFileChangeHooksParams
@@ -59,6 +59,8 @@ export interface CodeSearchParams {
5959
flags?: string
6060
/** Optional working directory to search within, relative to the project root. Defaults to searching the entire project. */
6161
cwd?: string
62+
/** Maximum number of results to return. Defaults to 30. */
63+
maxResults?: number
6264
}
6365

6466
/**
@@ -74,15 +76,23 @@ export interface FindFilesParams {
7476
prompt: string
7577
}
7678

79+
/**
80+
* Retrieve information about an agent by ID
81+
*/
82+
export interface LookupAgentInfoParams {
83+
/** Agent ID (short local or full published format) */
84+
agentId: string
85+
}
86+
7787
/**
7888
* Fetch up-to-date documentation for libraries and frameworks using Context7 API.
7989
*/
8090
export interface ReadDocsParams {
81-
/** The exact library or framework name (e.g., "Next.js", "MongoDB", "React"). Use the official name as it appears in documentation, not a search query. */
91+
/** The library or framework name (e.g., "Next.js", "MongoDB", "React"). Use the official name as it appears in documentation if possible. Only public libraries available in Context7's database are supported, so small or private libraries may not be available. */
8292
libraryTitle: string
83-
/** Optional specific topic to focus on (e.g., "routing", "hooks", "authentication") */
84-
topic?: string
85-
/** Optional maximum number of tokens to return. Defaults to 10000. Values less than 10000 are automatically increased to 10000. */
93+
/** Specific topic to focus on (e.g., "routing", "hooks", "authentication") */
94+
topic: string
95+
/** Optional maximum number of tokens to return. Defaults to 20000. Values less than 10000 are automatically increased to 10000. */
8696
max_tokens?: number
8797
}
8898

@@ -120,7 +130,7 @@ export interface RunTerminalCommandParams {
120130
* Set the conversation history to the provided messages.
121131
*/
122132
export interface SetMessagesParams {
123-
messages: Message[]
133+
messages: any
124134
}
125135

126136
/**
@@ -129,7 +139,7 @@ export interface SetMessagesParams {
129139
export interface SetOutputParams {}
130140

131141
/**
132-
* Spawn multiple agents and send a prompt to each of them.
142+
* Spawn multiple agents and send a prompt and/or parameters to each of them. These agents will run in parallel. Note that that means they will run independently. If you need to run agents sequentially, use spawn_agents with one agent at a time instead.
133143
*/
134144
export interface SpawnAgentsParams {
135145
agents: {

backend/src/tools/definitions/list.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { codeSearchTool } from './tool/code-search'
77
import { createPlanTool } from './tool/create-plan'
88
import { endTurnTool } from './tool/end-turn'
99
import { findFilesTool } from './tool/find-files'
10+
import { lookupAgentInfoTool } from './tool/lookup-agent-info'
1011
import { readDocsTool } from './tool/read-docs'
1112
import { readFilesTool } from './tool/read-files'
1213
import { runFileChangeHooksTool } from './tool/run-file-change-hooks'
@@ -34,6 +35,7 @@ const toolDescriptions = {
3435
create_plan: createPlanTool,
3536
end_turn: endTurnTool,
3637
find_files: findFilesTool,
38+
lookup_agent_info: lookupAgentInfoTool,
3739
read_docs: readDocsTool,
3840
read_files: readFilesTool,
3941
run_file_change_hooks: runFileChangeHooksTool,
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { getToolCallString } from '@codebuff/common/tools/utils'
2+
3+
import type { ToolDescription } from '../tool-def-type'
4+
5+
const toolName = 'lookup_agent_info'
6+
export const lookupAgentInfoTool = {
7+
toolName,
8+
description: `
9+
Retrieve information about an agent by ID for proper spawning. Use this when you see a request with a full agent ID like "@publisher/agent-id@version" to validate the agent exists and get its metadata. Only agents that are published under a publisher and version are supported for this tool.
10+
11+
Example:
12+
${getToolCallString(toolName, {
13+
agentId: 'codebuff/researcher@0.0.1',
14+
})}
15+
`.trim(),
16+
} satisfies ToolDescription

backend/src/tools/handlers/list.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { handleCodeSearch } from './tool/code-search'
55
import { handleCreatePlan } from './tool/create-plan'
66
import { handleEndTurn } from './tool/end-turn'
77
import { handleFindFiles } from './tool/find-files'
8+
import { handleLookupAgentInfo } from './tool/lookup-agent-info'
89
import { handleReadDocs } from './tool/read-docs'
910
import { handleReadFiles } from './tool/read-files'
1011
import { handleRunFileChangeHooks } from './tool/run-file-change-hooks'
@@ -40,6 +41,7 @@ export const codebuffToolHandlers = {
4041
create_plan: handleCreatePlan,
4142
end_turn: handleEndTurn,
4243
find_files: handleFindFiles,
44+
lookup_agent_info: handleLookupAgentInfo,
4345
read_docs: handleReadDocs,
4446
read_files: handleReadFiles,
4547
run_file_change_hooks: handleRunFileChangeHooks,
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import { removeUndefinedProps } from '@codebuff/common/util/object'
2+
import { getAgentTemplate } from '../../../templates/agent-registry'
3+
4+
import type { CodebuffToolHandlerFunction } from '../handler-function-type'
5+
import z from 'zod/v4'
6+
7+
export const handleLookupAgentInfo: CodebuffToolHandlerFunction<
8+
'lookup_agent_info'
9+
> = (params) => {
10+
const { agentId } = params.toolCall.input
11+
12+
return {
13+
result: (async () => {
14+
const agentTemplate = await getAgentTemplate(
15+
agentId,
16+
params.state.localAgentTemplates || {},
17+
)
18+
19+
if (!agentTemplate) {
20+
return [
21+
{
22+
type: 'json',
23+
value: {
24+
found: false,
25+
error: `Agent '${agentId}' not found`,
26+
},
27+
},
28+
]
29+
}
30+
const {
31+
id,
32+
displayName,
33+
model,
34+
includeMessageHistory,
35+
inputSchema,
36+
spawnerPrompt,
37+
outputMode,
38+
outputSchema,
39+
toolNames,
40+
spawnableAgents,
41+
} = agentTemplate
42+
43+
return [
44+
{
45+
type: 'json',
46+
value: {
47+
found: true,
48+
agent: {
49+
...removeUndefinedProps({
50+
fullAgentId: agentId,
51+
id,
52+
displayName,
53+
model,
54+
toolNames,
55+
spawnableAgents,
56+
includeMessageHistory,
57+
spawnerPrompt,
58+
...(inputSchema && {
59+
inputSchema: inputSchemaToJSONSchema(inputSchema),
60+
}),
61+
outputMode,
62+
...(outputSchema && {
63+
outputSchema: toJSONSchema(outputSchema),
64+
}),
65+
}),
66+
},
67+
},
68+
},
69+
]
70+
})(),
71+
}
72+
}
73+
74+
const toJSONSchema = (schema: z.ZodSchema) => {
75+
const jsonSchema = z.toJSONSchema(schema, { io: 'input' }) as {
76+
[key: string]: any
77+
}
78+
delete jsonSchema['$schema']
79+
return jsonSchema
80+
}
81+
82+
const inputSchemaToJSONSchema = (inputSchema: {
83+
prompt?: z.ZodSchema
84+
params?: z.ZodSchema
85+
}) => {
86+
return removeUndefinedProps({
87+
prompt: inputSchema.prompt ? toJSONSchema(inputSchema.prompt) : undefined,
88+
params: inputSchema.params ? toJSONSchema(inputSchema.params) : undefined,
89+
})
90+
}

common/src/templates/initial-agents-dir/types/tools.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export type ToolName =
66
| 'code_search'
77
| 'end_turn'
88
| 'find_files'
9+
| 'lookup_agent_info'
910
| 'read_docs'
1011
| 'read_files'
1112
| 'run_file_change_hooks'
@@ -26,6 +27,7 @@ export interface ToolParamsMap {
2627
code_search: CodeSearchParams
2728
end_turn: EndTurnParams
2829
find_files: FindFilesParams
30+
lookup_agent_info: LookupAgentInfoParams
2931
read_docs: ReadDocsParams
3032
read_files: ReadFilesParams
3133
run_file_change_hooks: RunFileChangeHooksParams
@@ -74,6 +76,14 @@ export interface FindFilesParams {
7476
prompt: string
7577
}
7678

79+
/**
80+
* Retrieve information about an agent by ID
81+
*/
82+
export interface LookupAgentInfoParams {
83+
/** Agent ID (short local or full published format) */
84+
agentId: string
85+
}
86+
7787
/**
7888
* Fetch up-to-date documentation for libraries and frameworks using Context7 API.
7989
*/

common/src/tools/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export const toolNames = [
2525
'create_plan',
2626
'end_turn',
2727
'find_files',
28+
'lookup_agent_info',
2829
'read_docs',
2930
'read_files',
3031
'run_file_change_hooks',
@@ -46,6 +47,7 @@ export const publishedTools = [
4647
'code_search',
4748
'end_turn',
4849
'find_files',
50+
'lookup_agent_info',
4951
'read_docs',
5052
'read_files',
5153
'run_file_change_hooks',

common/src/tools/list.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { codeSearchParams } from './params/tool/code-search'
88
import { createPlanParams } from './params/tool/create-plan'
99
import { endTurnParams } from './params/tool/end-turn'
1010
import { findFilesParams } from './params/tool/find-files'
11+
import { lookupAgentInfoParams } from './params/tool/lookup-agent-info'
1112
import { readDocsParams } from './params/tool/read-docs'
1213
import { readFilesParams } from './params/tool/read-files'
1314
import { runFileChangeHooksParams } from './params/tool/run-file-change-hooks'
@@ -43,6 +44,7 @@ export const $toolParams = {
4344
create_plan: createPlanParams,
4445
end_turn: endTurnParams,
4546
find_files: findFilesParams,
47+
lookup_agent_info: lookupAgentInfoParams,
4648
read_docs: readDocsParams,
4749
read_files: readFilesParams,
4850
run_file_change_hooks: runFileChangeHooksParams,

0 commit comments

Comments
 (0)