Gwenflow is built from a handful of objects that compose: an LLM client talks to a provider, an agent drives it in a loop with tools and a history, and a flow chains agents and data steps in a graph. Everything else (skills, memory, retrieval, durability, telemetry) attaches to one of these.

The building blocks

A run, step by step

  1. System prompt. Built from the agent’s instructions (or a fixed system_prompt), the list of its skills, its long-term memory, the JSON schema of a response_model, references from its retriever and the context passed to the run.
  2. History. The new message joins the agent’s history. Before every request the history is measured against the model’s context window and compacted when it nears the limit.
  3. Model call. The LLM client sends the history and the tool schemas, and returns a provider-neutral ModelResponse.
  4. Tools. Each tool call is executed and its result appended as a tool message; the loop goes back to the model. Calls to delegated agents (team members, sub-agents) run in parallel.
  5. Answer. When the model answers without calling a tool, the run ends with finish_reason="stop". It also ends at max_turns, or pauses when a tool needs a human’s approval.

Sync, async and streaming

Every operation has four forms, with the same arguments: A stream yields events as they happen (text deltas, thinking, tool starts and ends) and ends with the complete response. See Streaming.

Lazy imports

import gwenflow stays light: the vendor SDKs (anthropic, google-genai, mistralai), the tools, the readers and the MCP client load on first use. from gwenflow import ChatAnthropic works as usual; the SDK is only imported at that moment. Avoid from gwenflow import *, which resolves every name and loses the saving.

Identifiers

Agents, runs, responses and flows get UUIDv7 identifiers: unique and sortable by creation time. Inside a Temporal workflow they are generated deterministically, so a replay produces the same ones.