session workflow - kongusen/loom-agent GitHub Wiki
Use this pattern when later runs need continuity from earlier runs.
- multi-step product flows
- coding copilots with follow-up questions
- iterative planning and refinement
- user-specific assistant sessions
from loom import Agent, Model, RunContext, Runtime, SessionConfig
agent = Agent(
model=Model.anthropic("claude-sonnet-4"),
instructions="You help users refine API designs across multiple turns.",
runtime=Runtime.sdk(),
)
session = agent.session(SessionConfig(id="user-123"))
first = await session.run("List three options for versioning an API")
second = await session.run(
"Recommend one option for a startup team",
context=RunContext(inputs={"previous_answer": first.output}),
)Use Session for continuity and RunContext for explicit per-run inputs.
That split keeps the contract clear:
- session state is long-lived
-
RunContextis request-scoped
- add
SessionRestorePolicywhen reopening a durable session - add
FileSessionStorewhen state must survive process restart - add
KnowledgeBundleinRunContextwhen grounding is needed on one run