mirror of
https://github.com/agent0ai/agent-zero.git
synced 2026-10-19 07:23:51 +00:00
Optimize scoped tool policy resolution
Reuse one fresh policy snapshot across tool prompt and Responses schema batches while keeping execution-time enforcement current. Add adversarial coverage for cross-agent isolation and policy changes after tool advertisement.
This commit is contained in:
parent
6a6cecff85
commit
1432bde85e
6 changed files with 155 additions and 26 deletions
|
|
@ -35,18 +35,21 @@ async def build_prompt(agent: Agent) -> str:
|
|||
# per-file kwargs registered by plugin config extensions (e.g. _09_text_editor_config)
|
||||
all_tool_kwargs: dict[str, dict[str, Any]] = agent.get_data(TOOL_KWARGS_KEY) or {}
|
||||
|
||||
tools: list[str] = []
|
||||
tool_prompts: list[tuple[str, str]] = []
|
||||
for tool_file in tool_files:
|
||||
try:
|
||||
basename = os.path.basename(tool_file)
|
||||
extra = all_tool_kwargs.get(basename, {})
|
||||
tool = agent.read_prompt(basename, **extra)
|
||||
tool = tool_policy.filter_tool_prompt(agent, basename, tool)
|
||||
if tool:
|
||||
tools.append(tool)
|
||||
tool_prompts.append((basename, tool))
|
||||
except Exception as e:
|
||||
PrintStyle().error(f"Error loading tool '{tool_file}': {e}")
|
||||
|
||||
tools = [
|
||||
tool
|
||||
for tool in tool_policy.filter_tool_prompts(agent, tool_prompts)
|
||||
if tool
|
||||
]
|
||||
tools_str = "\n\n".join(tools)
|
||||
prompt = agent.read_prompt("agent.system.tools.md", tools=tools_str)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue