Calls and sessions
Choose when to open a session and how to manage resources across calls.
When do you need a session?
A session keeps SDK resources open while your Agent works. If you pass a checkpointer or a resources factory, open a session with with agent or async with agent before the first call, even for a single request.
| Your task | What to use | Why |
|---|---|---|
| One request or batch without a checkpointer or resources factory | invoke/batch, or await ainvoke/abatch | Automatic temporary session and cleanup. |
| Long-lived service | One explicit session for the service lifespan | Reuse SDK resources across requests. |
| Incremental results | Explicit session plus stream/astream | Keep resources open until the stream closes. |
| Conversation with saved state | Explicit session plus thread and checkpointer | Read the same authorized conversation state on later calls. |
Choose Sync for a synchronous script and Async inside an existing event loop. Use the same mode throughout a session. Inside a running event loop, await the async methods and avoid nesting asyncio.run.
Keep a session open across requests
Use your configured model, tools and openeight_config. The example processes your requests in one session. In a web service, open the session at startup and close it at shutdown.
from openeight.langchain import create_agent
agent = create_agent(
model=model,
tools=tools,
openeight=openeight_config,
)
with agent:
for inputs in requests:
result = agent.invoke(inputs)
process_result(result)Each request produces its own Run. Exiting the context closes the session.
Who closes each resource?
The SDK closes resources it creates, such as transport and delivery workers. Your application keeps ownership of models, backends and savers passed directly to the agent, so keep them alive until agent cleanup finishes. If you use resources=, create and close any checkpointer or store in that factory and omit both constructor arguments. Pass your model directly.
Invocation and batch
Each new input starts its own Run. Keep resources open until the Agent finishes processing the inputs it has accepted.
Concurrency and batch failures
Open a sync Agent session once and make one call at a time. The SDK rejects nested sessions and overlapping calls on that Agent. For concurrent requests, use a separate sync Agent per thread or make async calls on the event loop where you opened the Agent.
Calls on the same checkpoint thread must run sequentially. If a batch fails early, the Agent finishes handling inputs it already accepted before it can take another call.
Tell us how your Agent handles requests and when it needs to release resources. Keep credentials and private application data out of your message.
Email us at hello@openeight.ai.