Skip to main content
note

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:

  1. Status: A processing status event
  2. Chunk: A single response message chunk
  3. Status: A ready status event
  4. 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:

  1. βœ… 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.

  2. πŸ’¬ 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.

  3. βœ… Agent Ready
    Emits a status event indicating that the agent is ready to accept new events.

  4. βœ… 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, and completed status events.

πŸš€ Usage​

This runner is designed to be used directly within the Flux0 framework. To try it out, follow these steps:

  1. Create an agent that uses this runner
    Use the flux0 CLI to register a new agent with the runner type static_agent (as defined by the @agent_runner("static_agent") decorator):

    flux0 agents create --name static --type static_agent
  2. Open the chat UI
    Navigate to the Flux0 chat interface in your browser:

    http://localhost:8080/chat

  3. Start a session
    Select the static 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