Hi, is there a way of intercepting the agents' int...
# questions
f
Hi, is there a way of intercepting the agents' interactions at any point, send it a new prompt and then have it continue the interaction?
c
One thing we do, already, in openhands, is that we subscribe to the event stream, and look at the incoming event, and make some decision/insert something/change some behavior
f
Can I calls this somehow from the command line during an interaction? I am running it in headless mode, and the idea would be that at any point in the interaction, I can jump in and give new instructions
Without killing the run
c
Yes, it’s an event stream in any way you run OH
Register a listener, and do whatever you like in the listener code
@nutritious-balloon-65098 Add a comment to PR https://github.com/All-Hands-AI/OpenHands/pull/10566 about this: the prompt for the event_stream.mdx file MUST include a section named Event Stream Subscription Mechanism, in which we document the subscription mechanism and give an example of real world use
n
I'm on it! can track my progress here.
f
Ah ok! How can I register an event listener? Do I need to write the listner code before starting the run or can I do this live while the agent is already having interactions
For now, in our use case, its ok if I need to define the listnere code before
n
Summary I successfully added a comment to PR #10566 (https://github.com/All-Hands-AI/OpenHands/pull/10566) addressing your requirement about the Event Stream Subscription Mechanism documentation. What I accomplished: ✅ Added a comprehensive PR comment that clearly states the requirement: The prompt for the
event_stream.mdx
file MUST include a section named "Event Stream Subscription Mechanism" with real-world usage examples. ✅ Provided context and justification explaining why this is important: • Event Stream Subscription allows intercepting agent interactions at any point • Users need to understand how to subscribe to monitor/modify agent behavior • Real-world use cases include headless mode interception and dynamic instruction injection ✅ Referenced existing functionality by citing the code example you mentioned (
openhands/server/conversation_manager/standalone_conversation_manager.py#L356
) ✅ Gave actionable guidance suggesting that the
architecture_refresh.j2
prompt should be updated to specifically require this section The comment is now live at: https://github.com/All-Hands-AI/OpenHands/pull/10566#issuecomment-3214114626 This ensures that when the weekly architecture documentation automation runs, it will properly document the event stream subscription mechanism with real-world examples, exactly as you requested. No code changes were made - this was purely a documentation requirement communicated via PR comment, which was the appropriate action for this request. <sub>View full conversation</sub>
c
@fancy-salesmen-9987 Trying to find a better example or make it in headless…
So I think you need somehow to get hold of the event stream for the run, and that is possible via the runtime, but it does mean you need to write a small script that first uses
create_runtime
, then picks up the event stream and registers your listener, then starts the actual run
run_controller
with that runtime instance 🤔
This is too complicated, it shouldn’t be
f
mmh, i'm having trouble understanding how we would execute the listener code at any point in the interaction, while it is still running? what's the interface for interacting with the agent once its running
we would want to attach to the current runtime, no? instead of creating a new runtime instance with the listener
c
mmh, i'm having trouble understanding how we would execute the listener code at any point in the interaction, while it is still running? what's the interface for interacting with the agent once its running
When the event stream adds an event, any event (e.g. the action from the LLM, the observation from executing it, a message from the agent or from user), it calls all listeners
🤔 So you can insert an event… a message from you. But I’m not so sure anymore that it works without issues in headless mode, I just realized that maybe it will run into trouble if you insert events (as opposed to just read them) I had the agent start another branch, where we will define an interface for the client developer to implement, and test how it works with headless
👍 1
f
Thanks!
Sorry, maybe I'm misunderstanding, but how exactly could I insert an event in headless mode from the command line when the agent is running?
c
So my thinking here is: • you have the event stream reference (the one you registered the listener on) • you can create a user message event • and add it with event_stream.add_event…
f
I see, but this will not be done live while the agent is running? I think my idea would be that I don't know prior at what point in the trajectory I want to intercept the agents
c
You’d thinking like, you look at what they do, and then just send a user message?
👍 1
If so, is there a reason why you wouldn’t use the CLI mode? Rather than headless. It seems like it may be easier because it’s meant to be interactive: you can at any time press Ctrl+P, it pauses, you can enter your feedback, and it continues
f
mmh yes, in our case its important that we can use the agent programmatically, so the CLI mode is not an option unfortunately
c
Could you tell a little more about your use case? So you start it via
main.py
, but at some point you’d like to insert events, how, is that the user writing a message, or…?
You say you don’t know in advance where you want to intercept the agent
so I thought you’d run it in an interactive manner, you would like to intervene?