feat(api): inject folder manifest into home agent when project context active
Add optional project_id param to run_home_stream. When set, fetch the linked folder manifest via _fetch_project_manifest and prepend the <linked_folder> block to the system prompt. Also build an explicit tools list that extends _all_tools_for_user with FOLDER_TOOLS so the home agent can read folder files. device_ws._handle_home_request extracts project_id / projectId from the home_request frame and forwards it to the runner. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -228,11 +228,13 @@ async def _handle_home_request(
|
||||
request_id = frame.get("request_id") or str(uuid4())
|
||||
message: str = frame.get("message", "")
|
||||
session_id: str = frame.get("session_id") or str(uuid4())
|
||||
project_id: str | None = frame.get("project_id") or frame.get("projectId") or None
|
||||
logger.info(
|
||||
"device_ws: home_request_start user=%s req=%s session=%s msg=%s",
|
||||
"device_ws: home_request_start user=%s req=%s session=%s project=%s msg=%s",
|
||||
user_id,
|
||||
request_id,
|
||||
session_id,
|
||||
project_id,
|
||||
message[:200],
|
||||
)
|
||||
|
||||
@@ -257,7 +259,7 @@ async def _handle_home_request(
|
||||
set_client_executor(executor)
|
||||
response_chunks: list[str] = []
|
||||
try:
|
||||
event_stream = run_home_stream(user_id, message, context)
|
||||
event_stream = run_home_stream(user_id, message, context, project_id=project_id)
|
||||
formatter = StreamFormatter(request_id=request_id)
|
||||
async for ws_frame in formatter.format(event_stream):
|
||||
await websocket.send_text(ws_frame.model_dump_json())
|
||||
|
||||
@@ -1378,9 +1378,22 @@ async def run_home_stream(
|
||||
user_id: str,
|
||||
message: str,
|
||||
context: dict[str, Any],
|
||||
project_id: str | None = None,
|
||||
) -> AsyncGenerator[tuple[str, Any], None]:
|
||||
from app.agents.folder_agent import FOLDER_TOOLS
|
||||
|
||||
prepared_context = await _prepare_context(message, context)
|
||||
system_prompt, langfuse_prompt = _build_system_prompt("home_system", _HOME_SYSTEM_PROMPT, prepared_context)
|
||||
|
||||
manifest_block = ""
|
||||
if project_id:
|
||||
manifest = await _fetch_project_manifest(project_id)
|
||||
manifest_block = format_folder_manifest(manifest)
|
||||
system_prompt = system_prompt + ("\n\n" + manifest_block if manifest_block else "")
|
||||
|
||||
trace_id = _trace_id_from_context(prepared_context)
|
||||
tools = [*_all_tools_for_user(user_id, trace_id), *FOLDER_TOOLS]
|
||||
|
||||
text_chunks: list[str] = []
|
||||
async for event in _run_single_agent_stream(
|
||||
user_id=user_id,
|
||||
@@ -1389,6 +1402,7 @@ async def run_home_stream(
|
||||
context=prepared_context,
|
||||
langfuse_prompt=langfuse_prompt,
|
||||
agent_name="home-agent",
|
||||
tools=tools,
|
||||
conversation_history=context.get("conversation_history"),
|
||||
):
|
||||
event_type, data = event
|
||||
|
||||
Reference in New Issue
Block a user