Skip to content

Commit 378a77c

Browse files
committed
refactor(agent): polishing
1 parent fdc3a53 commit 378a77c

File tree

3 files changed

+62
-2
lines changed

3 files changed

+62
-2
lines changed

src/agent/src/agent.lua

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,32 @@ function agent:step(prompt_builder, runtime_options)
504504
options.stream = runtime_options.stream_target
505505
end
506506

507+
--if has_tools_with_schemas(self.tools) then
508+
-- options.tools = extract_tool_schemas_for_llm(self.tools)
509+
--
510+
-- -- DEBUG: Print tools being sent to LLM
511+
-- print("=== TOOLS SENT TO LLM ===")
512+
-- for i, tool in ipairs(options.tools) do
513+
-- print(string.format("Tool %d: %s", i, tool.name))
514+
-- print(" Description:", tool.description or "nil")
515+
-- print(" Registry ID:", tool.registry_id or "nil")
516+
-- if tool.meta then
517+
-- local meta_keys = {}
518+
-- for k, _ in pairs(tool.meta) do
519+
-- table.insert(meta_keys, k)
520+
-- end
521+
-- print(" Meta keys:", table.concat(meta_keys, ", "))
522+
-- print(" Meta content:", json.encode(tool.meta))
523+
-- else
524+
-- print(" Meta: nil")
525+
-- end
526+
-- print(" Schema present:", tool.schema and "yes" or "no")
527+
-- print("---")
528+
-- end
529+
-- print("=== END TOOLS DEBUG ===")
530+
--end
531+
532+
507533
local result, err = llm_instance.generate(final_messages, options)
508534
if err then
509535
return nil, err

src/agent/src/compiler/compiler.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,21 +296,25 @@ local function process_tools(raw_spec, additional_tools, trait_contexts, trait_t
296296
tool_entry.description = tool_info.description or ("Inline tool: " .. canonical_name)
297297
tool_entry.schema = tool_info.inline_schema
298298
tool_entry.registry_id = nil
299+
tool_entry.meta = {}
299300
else
300301
if trait_tool_schemas[canonical_name] then
301302
tool_entry.description = tool_info.description or trait_tool_schemas[canonical_name].description or ("Trait tool: " .. canonical_name)
302303
tool_entry.schema = trait_tool_schemas[canonical_name].schema
303304
tool_entry.registry_id = tool_info.id
305+
tool_entry.meta = trait_tool_schemas[canonical_name].meta or {}
304306
else
305307
local original_schema, err = get_tools().get_tool_schema(tool_info.id)
306308
if original_schema then
307309
tool_entry.description = tool_info.description or original_schema.description
308310
tool_entry.schema = original_schema.schema
309311
tool_entry.registry_id = tool_info.id
312+
tool_entry.meta = original_schema.meta or {}
310313
else
311314
tool_entry.description = tool_info.description or ("Tool: " .. canonical_name)
312315
tool_entry.schema = nil
313316
tool_entry.registry_id = tool_info.id
317+
tool_entry.meta = {}
314318
end
315319
end
316320
end

src/agent/src/discovery/tools.lua

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,36 @@ local function run_input_schema_processors(input_schema, tool_id)
131131
return input_schema
132132
end
133133

134+
-- Filter out meta fields that are already extracted for LLM tool construction
135+
local function filter_meta_for_llm(meta)
136+
if not meta then
137+
return {}
138+
end
139+
140+
local filtered = {}
141+
142+
-- Fields already extracted and used in tool construction, exclude them
143+
local excluded_fields = {
144+
input_schema = true,
145+
llm_description = true,
146+
llm_descirtion = true, -- typo variant
147+
llm_alias = true,
148+
title = true,
149+
description = true,
150+
comment = true,
151+
type = true, -- tool type marker, not needed by LLM
152+
name = true -- if present, already used
153+
}
154+
155+
for key, value in pairs(meta) do
156+
if not excluded_fields[key] then
157+
filtered[key] = value
158+
end
159+
end
160+
161+
return filtered
162+
end
163+
134164
-- Get the LLM-friendly tool name
135165
function tool_resolver.get_tool_name(entry)
136166
-- If llm_alias is specified, use that
@@ -222,7 +252,7 @@ function tool_resolver.get_tool_schema(tool_id)
222252
title = entry.meta.title or display_name,
223253
description = description,
224254
schema = run_input_schema_processors(schema, tool_id), -- Process input schema (cached separately)
225-
meta = entry.meta
255+
meta = filter_meta_for_llm(entry.meta) -- Filter out redundant fields
226256
}
227257

228258
return tool
@@ -330,7 +360,7 @@ function tool_resolver.find_tools(criteria)
330360
-- Add additional criteria
331361
if criteria then
332362
if criteria.namespace then
333-
query[".ns"] = criteria.namespace -- FIXED: Use .ns instead of ~namespace
363+
query[".ns"] = criteria.namespace -- ↠FIXED: Use .ns instead of ~namespace
334364
end
335365

336366
if criteria.tags and #criteria.tags > 0 then

0 commit comments

Comments
 (0)