Skip to main content

Flowstate

Flowstate is a small Python library for maintaining behavioral context for AI agents.

Instead of retrieval context from documents or knowledge context from static reference data, Flowstate keeps the user's live workflow state structured and current. Your agent reads it as background context before responding.

flowstate flowchart

Install

pip install flowstate-ai

Quick start

Create one context per session and update it as the user moves through your product:

from flowstate import Context

ctx = Context(scope={"user_id": "traveller-301"}, max_steps=4)

# traveller opens their booking and sees a delay
ctx.set_fact("flight", "BA 442 — London Heathrow to Amsterdam")
ctx.set_fact("scheduled_departure", "16:45")
ctx.set_fact("status", "Delayed — 2 hours (new departure: 18:45)")
ctx.set_fact("gate", "B22, closes 18:15")
ctx.add_step("opened booking")
ctx.add_step("saw delay notification")
ctx.add_step("tapped 'Is my flight on time?'")
ctx.set_intent("task", "decide whether to leave for the airport now")

# traveller asks a question — agent already knows the full picture
messages = [ctx.as_message(), {"role": "user", "content": user_input}]

ctx.as_message() renders to:

Scope:
  user id: traveller-301

Facts:
  flight: BA 442 — London Heathrow to Amsterdam
  scheduled departure: 16:45
  status: Delayed — 2 hours (new departure: 18:45)
  gate: B22, closes 18:15

Steps:
  opened booking
  saw delay notification
  tapped 'Is my flight on time?'

Intent:
  task: decide whether to leave for the airport now

Demo

A traveller's flight is delayed. They open the app and type:

"Do I need to leave now?"

Your app has been watching. It knows which flight they're on, the new departure time, and when the gate closes. That gets passed to the assistant as background:

Facts:
  flight: BA 442 — London Heathrow to Amsterdam
  scheduled departure: 16:45
  status: Delayed — 2 hours (new departure: 18:45)
  gate: B22, closes 18:15

Steps:
  opened booking
  saw delay notification
  tapped 'Is my flight on time?'

Intent:
  task: decide whether to leave for the airport now
Assistant with background Assistant without
No rush — your flight has been pushed to 18:45 and gate B22 closes at 18:15. As long as you can reach Heathrow by 17:45 you're fine. You have about 2 extra hours compared to your original plan. Which flight are you on, and what time does it depart?

Without background the assistant can't answer at all.

python examples/evaluation.py
# → examples/evaluation_report.html

The model

Context has four sections:

Section Type Holds
scope dict Tenant, user, and session identifiers
facts dict Durable known state
steps list[str] Observed user progression
intent dict Current inferred goal

Updating context

Use individual setters for explicit writes:

ctx.set_fact("current_page", "settings reference")
ctx.add_step("opened settings reference")
ctx.set_intent("task", "understand a configuration error")

Use merge helpers when multiple app surfaces contribute to the same section:

ctx.merge_facts({
    "docs": {"current_page": "settings reference"},
    "errors": {"current_error": "ImproperlyConfigured"},
})

Use merge() to combine two independently built contexts:

ctx.merge(other_ctx)

Exports

ctx.render()      # plain text for prompts
ctx.as_message()  # {"role": "system", "content": ...} for chat APIs
ctx.to_dict()     # plain Python dict
ctx.to_schema()   # validated Pydantic model

Validation

Optional. Subclass ContextSchema to add Pydantic checks:

from flowstate import ContextSchema

class DocsContextSchema(ContextSchema):
    facts: dict[str, str]

validated = ctx.validate(DocsContextSchema)

Metadata

Release files for flowstate-ai 0.4.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for flowstate-ai 0.4.1
File Size Uploaded Provenance
flowstate_ai-0.4.1.tar.gz 9.8 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for flowstate-ai 0.4.1
File Interpreter ABI Platform
flowstate_ai-0.4.1-py3-none-any.whl Python 3 none any Details

Total release size: 18.0 kB

Release files / flowstate_ai-0.4.1.tar.gz

Download URL flowstate_ai-0.4.1.tar.gz
Size 9.8 kB
Tags Source
SHA-256 checksum
How to use checksums
baed9044a7fb36807c29134aa932e79b59a40f142d5815368616dbc1d591fce6
BLAKE2b-256 checksum
How to use checksums
046aed1a6b086f2d84f6564eda65c6edc911647bdd84cc248ddd1d5a01b843f0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.1

Release files / flowstate_ai-0.4.1-py3-none-any.whl

Download URL flowstate_ai-0.4.1-py3-none-any.whl
Size 8.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
49250c6250e04ca17572ad7ac0c6ff25fdad17bde6c765f8b93bdc5cfee4c411
BLAKE2b-256 checksum
How to use checksums
05f097ede4afb80eafe9b17fd573098b2e59b4f510cf552969d72c57f3fc0fad
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.1

Security for flowstate-ai 0.4.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.4.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page