Skip to content

feat(agent): add tool call prefix stripping and assistant prefill removal for proxy provider compatibility #224

Closed
xuandung38 wants to merge 3 commits into
nextlevelbuilder:mainfrom
xuandung38:feat/agent-tool-policy-enhancements
Closed

feat(agent): add tool call prefix stripping and assistant prefill removal for proxy provider compatibility #224
xuandung38 wants to merge 3 commits into
nextlevelbuilder:mainfrom
xuandung38:feat/agent-tool-policy-enhancements

Conversation

@xuandung38
Copy link
Copy Markdown
Contributor

Summary

Two per-agent options to support proxy LLM providers (LiteLLM, OpenRouter, etc.):

1. Tool Call Prefix Stripping

Proxy providers may prepend a prefix to tool call names returned by the model (e.g. proxy_exec instead of exec),
causing tool policy validation failures and registry lookup errors.

Per-agent toolCallPrefix config strips the prefix before registry lookup, permission checks, and
team_tasks/spawn detection in both serial and parallel paths. Supports literal prefixes (proxy_) and template
patterns (proxy_{tool_name}).

2. Strip Assistant Prefill

Some models/providers reject requests ending with an assistant-role message (HTTP 400: "This model does not support
assistant message prefill").

Per-agent strip_assistant_prefill toggle removes trailing assistant messages before sending to the LLM. Configurable
in LLM Configuration (General tab), stored in other_config.

Additional Fix

Config save handler now uses spread operator instead of hardcoded field list — new fields were silently dropped on
save.

@xuandung38 xuandung38 force-pushed the feat/agent-tool-policy-enhancements branch from 0f13bea to 327f175 Compare March 16, 2026 16:04
Proxy providers like LiteLLM and OpenRouter may prepend a prefix to
tool call names returned by the model (e.g. "proxy_exec" instead of
"exec"). This broke tool policy validation, registry lookup, and
hardcoded name checks for "team_tasks" and "spawn" in both serial
and parallel execution paths.

Add per-agent toolCallPrefix configuration that strips the configured
prefix from incoming tool call names before registry resolution. The
stripping is applied at resolveToolCallName() which is called before
permission checks, registry execution, and spawn/team_tasks detection.

- Add StripToolPrefix() supporting literal ("proxy_") and template
  ("{tool_name}") patterns
- Add toolCallPrefix to ToolPolicySpec with backward compat from old
  "toolPrefix" JSON key
- Fix config save using spread operator to prevent dropping new fields
- Add UI input in Tool Policy section with i18n (en/vi/zh)
…LM call

Some LLM providers and models do not support assistant message prefill
— requests ending with an assistant-role message get rejected with
HTTP 400 ("This model does not support assistant message prefill").
This happens when the system injects assistant messages to guide model
behavior or establish context.

Add per-agent strip_assistant_prefill toggle (stored in other_config)
that removes the trailing assistant message before constructing the
ChatRequest. The option is configurable in the LLM Configuration
section of the agent General tab.

- Add ParseStripAssistantPrefill() to AgentData (reads from other_config)
- Add stripAssistantPrefill field to Loop/LoopConfig
- Wire through resolver → loop
- Add checkbox UI in LLM Config section with i18n (en/vi/zh)
Add .gemini/, .claude/, .opencode/ to .gitignore to prevent
committing user-specific AI tool configurations.
@xuandung38
Copy link
Copy Markdown
Contributor Author

Closed it because I felt this PR had too much influence, so I split it into two PRs
#259 and #258

Fix Issue : 240

@xuandung38 xuandung38 closed this Mar 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant