Use BufferSlot as single source of truth for handler dispatch
Handlers now receive payload references directly from the context buffer slot rather than independent copies. Metadata is derived via slot_to_handler_metadata() ensuring consistency. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
f195835bea
commit
379f5a0258
1 changed files with 20 additions and 10 deletions
|
|
@ -381,9 +381,11 @@ class StreamPump:
|
||||||
|
|
||||||
# === CONTEXT BUFFER: Record incoming message ===
|
# === CONTEXT BUFFER: Record incoming message ===
|
||||||
# Append validated payload to thread's context buffer
|
# Append validated payload to thread's context buffer
|
||||||
|
# The returned BufferSlot becomes the single source of truth
|
||||||
|
slot = None
|
||||||
if current_thread and state.payload:
|
if current_thread and state.payload:
|
||||||
try:
|
try:
|
||||||
context_buffer.append(
|
slot = context_buffer.append(
|
||||||
thread_id=current_thread,
|
thread_id=current_thread,
|
||||||
payload=state.payload,
|
payload=state.payload,
|
||||||
from_id=state.from_id or "unknown",
|
from_id=state.from_id or "unknown",
|
||||||
|
|
@ -400,16 +402,24 @@ class StreamPump:
|
||||||
f"Thread {current_thread[:8]}... exceeded context buffer limit"
|
f"Thread {current_thread[:8]}... exceeded context buffer limit"
|
||||||
)
|
)
|
||||||
|
|
||||||
metadata = HandlerMetadata(
|
# Derive metadata from slot (single source of truth)
|
||||||
thread_id=current_thread,
|
# Fall back to manual construction if no slot (e.g., buffer overflow)
|
||||||
from_id=state.from_id or "",
|
if slot:
|
||||||
own_name=listener.name if listener.is_agent else None,
|
from agentserver.memory import slot_to_handler_metadata
|
||||||
is_self_call=is_self_call,
|
metadata = slot_to_handler_metadata(slot)
|
||||||
usage_instructions=listener.usage_instructions,
|
payload_ref = slot.payload # Same reference as in buffer
|
||||||
todo_nudge=todo_nudge,
|
else:
|
||||||
)
|
metadata = HandlerMetadata(
|
||||||
|
thread_id=current_thread,
|
||||||
|
from_id=state.from_id or "",
|
||||||
|
own_name=listener.name if listener.is_agent else None,
|
||||||
|
is_self_call=is_self_call,
|
||||||
|
usage_instructions=listener.usage_instructions,
|
||||||
|
todo_nudge=todo_nudge,
|
||||||
|
)
|
||||||
|
payload_ref = state.payload
|
||||||
|
|
||||||
response = await listener.handler(state.payload, metadata)
|
response = await listener.handler(payload_ref, metadata)
|
||||||
|
|
||||||
# None means "no response needed" - don't re-inject
|
# None means "no response needed" - don't re-inject
|
||||||
if response is None:
|
if response is None:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue