This content is from the README file of https://github.com/flux0-ai/flux0/tree/develop/examples/static. The source code for this example can be found here
π§ͺ Static Agent Runner Example for Flux0
This is a simple example of an AgentRunner that demonstrates streaming events to the client. Rather than invoking a real LLM or doing any computation, it statically emits events in a structured way to help developers understand how Flux0βs event streaming works.
β οΈ This runner emits static events for demonstration, but in a real setup, events would be dynamically generated by an LLM or other backend logic.
π¦ What It Doesβ
The StaticAgentRunner responds to a user's message with a fixed message and simulates processing by emitting a sequence of events, including:
- Status: A
processing
status event - Chunk: A single response message chunk
- Status: A
ready
status event - Status: A
completed
status event
It does not perform any real computation, language generation or tool invocation.
π Event Flowβ
Hereβs the sequence of events the runner emits:
-
β Processing Started
Emits a status event indicating that the agent is thinking, this is typically translated by the client UI into a "thinking" or "typing" indicator. -
π¬ Message Chunk Sent
Streams a single chunk containing a static message:"Hey there! I received your input: <user input>"
In a real-world setup, this would stream multiple chunks, each representing incremental tokens generated by an LLM. The client UI would display these chunks progressively to simulate real-time typing or streaming output from the model.
-
β Agent Ready
Emits a status event indicating that the agent is ready to accept new events. -
β Run Completed
Emits a final status event signaling that the entire run has successfully finished.
π Code Overviewβ
- Agent Lookup: Retrieves the agent by ID.
- Session History: Reads session events and extracts the most recent user message.
- Logging: Logs user input for debugging or observability.
- Simulated Delay: Waits 1.5 seconds to mimic processing time.
- Chunk Emission: Streams a static message chunk in response to the user input.
- Status Updates: Sends
processing
,ready
, andcompleted
status events.
π Usageβ
This runner is designed to be used directly within the Flux0 framework. To try it out, follow these steps:
-
Create an agent that uses this runner
Use theflux0
CLI to register a new agent with the runner typestatic_agent
(as defined by the@agent_runner("static_agent")
decorator):flux0 agents create --name static --type static_agent
-
Open the chat UI
Navigate to the Flux0 chat interface in your browser: -
Start a session
Select thestatic
agent and send a message. You'll see the runner simulate a response by streaming static content, along with status updates.
This is useful for testing:
- UI event rendering and streaming output
- Session event lifecycle
- Agent runner integration and orchestration