Overview
Thesession
context manager creates a new session, binds it to the current async/thread context, and automatically ends it when the context exits. This is the recommended pattern for self-contained workflows.
Syntax
Parameters
session_name
(string, optional): Display name for the session.session_id
(string, optional): Provide to resume under this ID; otherwise a new one is created.api_key
,agent_id
(string, optional): Credentials; fall back toLUCIDIC_API_KEY
andLUCIDIC_AGENT_ID
.task
,rubrics
,tags
(optional): Session metadata.providers
(list, optional): Instrumentation targets like"openai"
,"anthropic"
, etc.masking_function
(callable, optional): Mask sensitive data before sending.auto_end
(bool, optional): Ignored inside this context; session always ends on exit.
Returns
None. The active session is bound to context for the duration of thewith
block.
Examples
Notes
- Spans are stamped with the active
lucidic.session_id
at start for correct attribution. - Prefer this for request-scoped work or jobs that should clean up automatically.