sync update from LAN repo (source master @ ca48c4ec)
This commit is contained in:
1 parent
8bc8b0e082
commit
ea9dcff9c0
873 files changed
+107866
-14011
No files matched your search
+25
-5
@@ -35,6 +35,7 @@ from datetime import UTC, datetime
|
||||
from typing import Any
|
||||
|
||||
from deerflow.persistence.task_analysis.base import TaskAnalysisStore
|
||||
from deerflow.runtime.task_analysis.thread_metadata import task_analysis_thread_metadata
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -322,6 +323,7 @@ class ChainBindingExecutor:
|
||||
results = await asyncio.gather(
|
||||
*[
|
||||
self._run_seat(
|
||||
run_id=run_id,
|
||||
seat_id=seat_id,
|
||||
seat_name=seat_names.get(seat_id, seat_id),
|
||||
seat_description=descriptions.get(seat_id) or "",
|
||||
@@ -393,6 +395,7 @@ class ChainBindingExecutor:
|
||||
async def _run_seat(
|
||||
self,
|
||||
*,
|
||||
run_id: str,
|
||||
seat_id: str,
|
||||
seat_name: str,
|
||||
seat_description: str,
|
||||
@@ -408,6 +411,12 @@ class ChainBindingExecutor:
|
||||
note_live=None,
|
||||
) -> dict[str, Any]:
|
||||
thread_id = f"ta-seat-{seat_id}-{int(time.time() * 1000)}"
|
||||
thread_metadata = task_analysis_thread_metadata(
|
||||
task,
|
||||
run_id=run_id,
|
||||
role="seat",
|
||||
seat_id=seat_id,
|
||||
)
|
||||
prompt = self._build_seat_prompt(
|
||||
task=task,
|
||||
binding=binding,
|
||||
@@ -430,6 +439,7 @@ class ChainBindingExecutor:
|
||||
record = await self._start_seat_run(
|
||||
seat_id=seat_id, prompt=prompt, thread_id=thread_id, user_id=user_id,
|
||||
run_meta={"binding_id": binding["id"]},
|
||||
thread_metadata=thread_metadata,
|
||||
model_name=binding.get("model") or "",
|
||||
)
|
||||
if note_live is not None and record is not None:
|
||||
@@ -557,7 +567,14 @@ class ChainBindingExecutor:
|
||||
return "\n\n---\n\n".join(parts)
|
||||
|
||||
async def _start_seat_run(
|
||||
self, *, seat_id: str, prompt: str, thread_id: str, user_id: str, run_meta: dict[str, Any],
|
||||
self,
|
||||
*,
|
||||
seat_id: str,
|
||||
prompt: str,
|
||||
thread_id: str,
|
||||
user_id: str,
|
||||
run_meta: dict[str, Any],
|
||||
thread_metadata: dict[str, Any],
|
||||
model_name: str = "",
|
||||
):
|
||||
"""Run one seat round in-process (same trick as scheduler ``_start_agent_run``)."""
|
||||
@@ -574,10 +591,8 @@ class ChainBindingExecutor:
|
||||
assistant_id="lead_agent",
|
||||
input={"messages": [{"type": "human", "content": prompt}]},
|
||||
metadata={
|
||||
"thread_type": "task-analysis",
|
||||
"system": True,
|
||||
**thread_metadata,
|
||||
"task_analysis_binding_id": run_meta.get("binding_id"),
|
||||
"task_analysis_seat": seat_id,
|
||||
},
|
||||
context={
|
||||
"agent_name": seat_id,
|
||||
@@ -650,7 +665,12 @@ class ChainBindingExecutor:
|
||||
descriptions = {seat.get("agent_id"): seat.get("description") or "" for seat in snapshot_seats}
|
||||
|
||||
thread_id = await _create_thread_direct(
|
||||
request, metadata={"thread_type": "task-analysis", "system": True}
|
||||
request,
|
||||
metadata=task_analysis_thread_metadata(
|
||||
task,
|
||||
run_id=run["id"],
|
||||
role="coordinator",
|
||||
),
|
||||
)
|
||||
if note_live is not None:
|
||||
await note_live(COORDINATOR_SEAT, thread_id=thread_id)
|
||||
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
"""Metadata contract for task-analysis runtime threads.
|
||||
|
||||
The LangGraph checkpoint is still the canonical transcript for a coordinator
|
||||
or a seat. These markers make that implementation detail unambiguous to the
|
||||
general thread registry: task-analysis transcripts belong to a task-analysis
|
||||
run and must never be presented as ordinary Q&A conversations.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
|
||||
def task_analysis_thread_metadata(
|
||||
task: dict[str, Any],
|
||||
*,
|
||||
run_id: str | None = None,
|
||||
thread_type: str = "task-analysis",
|
||||
role: str | None = None,
|
||||
seat_id: str | None = None,
|
||||
) -> dict[str, Any]:
|
||||
"""Build durable metadata for one internal task-analysis transcript.
|
||||
|
||||
``task_analysis_task_id`` points at the dedicated ``task_analysis_tasks``
|
||||
row; the source id is retained for operators and external-system tracing.
|
||||
The fields are intentionally distinct from the task deep-link ``taskId``
|
||||
namespace, whose access and history semantics are different.
|
||||
"""
|
||||
|
||||
metadata: dict[str, Any] = {
|
||||
"thread_type": thread_type,
|
||||
"system": True,
|
||||
}
|
||||
task_id = task.get("id")
|
||||
if task_id is not None and str(task_id).strip():
|
||||
metadata["task_analysis_task_id"] = str(task_id)
|
||||
source_task_id = task.get("source_task_id")
|
||||
if source_task_id is not None and str(source_task_id).strip():
|
||||
metadata["task_analysis_source_task_id"] = str(source_task_id)
|
||||
if run_id and run_id.strip():
|
||||
metadata["task_analysis_run_id"] = run_id
|
||||
if role and role.strip():
|
||||
metadata["task_analysis_role"] = role
|
||||
if seat_id and seat_id.strip():
|
||||
metadata["task_analysis_seat"] = seat_id
|
||||
return metadata
|
||||
Reference in new issue
Block a user