feat(beta): set up a debug server to visualize memory streams#2496
feat(beta): set up a debug server to visualize memory streams#2496jsun-m wants to merge 27 commits into
Conversation
|
@jsun-m it's great initiative! But, what to you think about smth simpler? Like regular https://docs.python.org/3/library/pdb.html integration It seems like we can just introduce interceptors for all stream events? stream = MemoryStream()
@stream.subscriber(intercept=True)
async def debug_subscriber(event):
breakpoint()
return event
agent = Agent(...)
await agent.ask(..., stream=stream) |
hey nikita, I think i want less on the breakpointing and more and the visualization of the memory state. I remove breakpointing for now. |
| try { | ||
| const url = new URL(safePath, window.location.origin); | ||
| if (url.origin !== window.location.origin) return null; | ||
| const r = await fetch(url.href, opts); |
Check failure
Code scanning / CodeQL
Server-side request forgery Critical
Copilot Autofix
AI 3 months ago
Copilot could not generate an autofix suggestion
Copilot could not generate an autofix suggestion for this alert. Try pushing a new commit or if the problem persists contact support.
There was a problem hiding this comment.
this is non-critical for a locally running server
|
|
||
| from .models import SessionView | ||
|
|
||
| _UI_FILE = Path(__file__).parent / "ui.html" |
There was a problem hiding this comment.
|
@Lancetnik addressed feedback. removed changes to agent.py |
Summary
AG2_DEBUG_SERVER_URLcheck, session creation, attach/close) fromAgent.ask(). The debugger is now a standalone middleware users pass explicitly viamiddleware=[DebugMiddleware].DebugMiddlewareintercepts events through middleware hooks (on_turn,on_llm_call,on_tool_execution) instead of subscribing to the stream. This fixes event ordering issues where the user's message appeared after the reply.AG2_DEBUG_SERVER_URLis set,DebugMiddlewareauto-creates aDebugSessionand closes it after the turn. Without the env var (and no pre-existing session), it's a silent pass-through.DebugSession._ensure_stream()registers new streams with the server on first event, correctly handling multi-agent sessions that span multiple streams.autogen.beta.debug.__init__wraps imports intry/except ImportErrorwith helpful messages pointing topip install "ag2[beta-debug]".importlib.resources: ReplacedPath(__file__).parent / "ui.html"withimportlib.resources.files()for proper package data access.Usage
Quick start (env var)
Explicit session (multi-call)