mirror of
https://github.com/tiennm99/DocsGPT.git
synced 2026-10-13 22:15:10 +00:00
Show the arguments a tool call sends, fixed values included
The approval card and a finished call showed what the model asked for, even where a fixed value replaced it. Calls now carry sent_arguments for the chat, leaving headers out since they may hold a fixed secret. The model's own arguments are kept as they were, because they are what later turns replay to it and it never sees fixed values.
This commit is contained in:
1 parent
52217d43be
commit
dba2de590b
9 files changed
+147
-7
No files matched your search
@@ -14,7 +14,7 @@ from docsgpt.agents.default_tools import (
|
||||
synthesized_default_tools,
|
||||
)
|
||||
from docsgpt import tracing
|
||||
from docsgpt.agents.tool_pins import iter_parameters, llm_fills, resolve_arguments
|
||||
from docsgpt.agents.tool_pins import iter_parameters, llm_fills, resolve_arguments, sent_arguments, shown_arguments
|
||||
from docsgpt.agents.tools.tool_action_parser import ToolActionParser
|
||||
from docsgpt.agents.tools.tool_manager import ToolManager
|
||||
from docsgpt.guardrails.types import Stage as GuardrailStage, resolve_tool_result
|
||||
@@ -1102,6 +1102,12 @@ class ToolExecutor:
|
||||
"pause_type": "awaiting_approval",
|
||||
"thought_signature": getattr(call, "thought_signature", None),
|
||||
}
|
||||
# The card shows what will be sent: fixed values replace what the
|
||||
# model asked for. ``arguments`` stays as the model sent it, since
|
||||
# resuming replays it to the model, which never sees fixed values.
|
||||
sent = sent_arguments(action_data, arguments, self._connection_parameters(tool_data))
|
||||
if action_data and sent != arguments:
|
||||
payload["sent_arguments"] = sent
|
||||
# Surface the device id so the approval UI can offer a
|
||||
# "don't ask again" sticky-pattern action for remote devices.
|
||||
if tool_data.get("name") == "remote_device":
|
||||
@@ -1482,6 +1488,11 @@ class ToolExecutor:
|
||||
sections = resolve_arguments(action_data, call_args, self._connection_parameters(tool_data))
|
||||
query_params, headers = sections["query_params"], sections["headers"]
|
||||
body, parameters = sections["body"], sections["parameters"]
|
||||
# The chat shows what was sent; ``arguments`` keeps what the model
|
||||
# asked for, which is what a later turn replays to it.
|
||||
sent = shown_arguments(sections)
|
||||
if sent != (call_args if isinstance(call_args, dict) else {}):
|
||||
tool_call_data["sent_arguments"] = sent
|
||||
|
||||
# Load tool (with caching)
|
||||
from docsgpt.connectors.service import ConnectionUnavailable
|
||||
|
||||
@@ -104,6 +104,32 @@ def resolve_arguments(
|
||||
return resolved
|
||||
|
||||
|
||||
def shown_arguments(sections: Mapping[str, Mapping[str, Any]]) -> dict:
|
||||
"""One flat ``{parameter: value}`` view of resolved sections, for the chat.
|
||||
|
||||
Headers are left out: they may carry a pinned secret (an API key the
|
||||
owner fixed), and the chat is shown to whoever runs the agent.
|
||||
"""
|
||||
shown: dict = {}
|
||||
for section in PARAM_SECTIONS:
|
||||
if section != "headers":
|
||||
shown.update(sections.get(section) or {})
|
||||
return shown
|
||||
|
||||
|
||||
def sent_arguments(
|
||||
action: Mapping,
|
||||
llm_arguments: Mapping[str, Any],
|
||||
connection_pins: Optional[Mapping[str, Any]] = None,
|
||||
) -> dict:
|
||||
"""What a call sends, flattened for display (see :func:`shown_arguments`).
|
||||
|
||||
The approval card and the finished call show this rather than what the
|
||||
model asked for, which fixed values may have replaced.
|
||||
"""
|
||||
return shown_arguments(resolve_arguments(action, llm_arguments, connection_pins))
|
||||
|
||||
|
||||
def coerce_value(details: Mapping, value: Any) -> Any:
|
||||
"""Check a value for a pin against the parameter's declared type.
|
||||
|
||||
|
||||
@@ -1240,6 +1240,9 @@ class LLMHandler(ABC):
|
||||
# can wire the sticky "don't ask again" button.
|
||||
if pause_info.get("device_id"):
|
||||
pause_data["device_id"] = pause_info["device_id"]
|
||||
# What will be sent once fixed values replace the model's.
|
||||
if pause_info.get("sent_arguments") is not None:
|
||||
pause_data["sent_arguments"] = pause_info["sent_arguments"]
|
||||
# A connection-backed tool whose account needs signing in: the
|
||||
# approval card becomes a Connect card.
|
||||
if pause_info.get("connection_required"):
|
||||
|
||||
Reference in new issue
Block a user