fix(agent-panel): forward currentUri to agent context#2912
Conversation
When a user selects a directory in the resource tree and switches to the Agent panel, the agent now knows which directory they selected. Changes: - Pass currentUri prop from route to AgentPanel component - Add current_dir field to BotChatRequest type and use-chat hook - Add current_dir to OpenVikingConnection model - Extract current_dir in agent loop and pass to ContextBuilder - Inject User-Selected Directory section into system prompt The field is optional — when omitted the existing behavior is unchanged. Closes volcengine#2883
qin-ctx
left a comment
There was a problem hiding this comment.
Requesting changes for the blocking prompt-injection/input-validation issue on current_dir.
| # user asks about "the current directory" this is the one they mean. | ||
| if self._current_dir: | ||
| parts.append( | ||
| f"## User-Selected Directory\n\nThe user has selected the following directory in the Studio resource tree. When the user refers to 'the current directory', they mean this one:\n`{self._current_dir}`" |
There was a problem hiding this comment.
[Bug] (blocking) current_dir comes from the chat request body and is inserted verbatim into the system prompt. A caller can POST a value containing newlines/backticks/instructions, or open Playground with a crafted selected URI, and that text becomes hidden system prompt content under ## User-Selected Directory. This also does not enforce the PR's stated behavior that only directory URIs are forwarded: a file URI or arbitrary text would still be accepted if provided directly. Please validate/sanitize this field before it reaches the prompt. If this input is intentionally trusted, please explain the trust boundary that makes that safe.
current_dir was interpolated verbatim into the system prompt inside a markdown code span. A value with a newline could open a new ## section (prompt injection); a value containing a backtick collapsed the wrapping into a fenced code block. Emit the value as a JSON object instead: newlines become literal \n (no new line in the prompt), backticks stay inside a JSON string the model reads as data, and all structural markdown chars are contained by the JSON structure. Fixes the root cause at the injection site without relying on directory-name character restrictions. Refs volcengine#2883
|
Fixed in 623569c. Good point. Instead I fixed the root cause at the injection site: the value is now emitted as a JSON object ( This does not validate that the value is a real directory. Per your note, that is a trust-boundary question: |
|
@qin-ctx Please review it again |
Summary
Fixes #2883. When a user selects a directory in the resource tree and switches to the Agent panel, the agent now receives the selected directory URI and can respond to questions like "list the current directory" correctly.
Changes
Frontend (4 files):
route.tsx: passcurrentUriprop toAgentPanelagent-panel.tsx: acceptcurrentUri, attach ascurrent_dirin send payloaduse-chat.ts: threadcurrent_dirthrough send options into request bodychat.ts: addcurrent_dir?: stringtoBotChatRequesttypeBackend (4 files):
openapi_models.py: addcurrent_dir: Optional[str]toOpenVikingConnectionopenapi.py: pass through the fieldloop.py: extractcurrent_dirfrom message metadata, pass toContextBuildercontext.py: inject## User-Selected Directorysection into system promptBehavior
current_diris optional — omitting it preserves existing behavior (zero breaking change)/) are forwarded; file URIs are notTesting
--with-bot, open Studio playgroundopenviking_listwith the selected directory URI