Documentation Index
Fetch the complete documentation index at: https://mintlify.com/withastro/flue/llms.txt
Use this file to discover all available pages before exploring further.
FlueContext<TPayload, TEnv> is the single argument to every Flue agent handler function. It carries everything the handler needs for a run: the agent instance id, a server-minted run id, the parsed request body, platform environment bindings, the raw HTTP request, a structured logger, and the init() method that creates a harness.
Type signature
Generic type parameters
| Parameter | Default | Description |
|---|---|---|
TPayload | any | Type of ctx.payload. Compile-time only — no runtime validation is performed. |
TEnv | Record<string, any> | Type of ctx.env. On Cloudflare, pass the Env interface generated by wrangler types. |
Properties
Agent instance id, taken from the URL
<id> segment (POST /agents/<name>/<id>). Identifies the durable runtime scope — one customer, repository, conversation, or other caller-defined boundary. Reuse the same id to continue the same agent instance; use a new id to start fresh.Server-minted identifier for this HTTP invocation. Unique per request. Useful for correlating logs and events to a specific run.
The request body, parsed from JSON. The type is
TPayload at compile time; there is no runtime schema validation. Validate with Valibot or another library if you need runtime safety.Platform environment bindings. On Node.js this is
process.env. On Cloudflare Workers this is the Worker environment object (bindings declared in wrangler.jsonc). Pass your Env interface as TEnv to get typed access to KV namespaces, R2 buckets, Durable Object bindings, etc.The standard Fetch API
Request for the current invocation. Use it to read headers, method, URL, and the raw body. Undefined when the agent is invoked outside an HTTP context (no non-HTTP triggers exist today, but the optional type keeps the contract sound when other trigger types ship).See Working with req below.Emit structured log events into the run event stream. See
FlueLogger below.Methods
Initialize a harness. Creates a
FlueHarness with the configured model, sandbox, tools, session store, and default role. Call this once (or multiple times for multiple named harnesses) at the top of your handler.See AgentInit for the full options reference and FlueHarness for the returned object.FlueLogger
ctx.log emits structured events that appear in the run event stream as { type: 'log', level, message, attributes }. Use it instead of console.log so log entries are correlated to the run and visible in observability tooling.
Working with req
ctx.req is a standard Fetch Request. Use it to read headers and inspect the raw body.