The high-levelDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/sidmanale643/northstar/llms.txt
Use this file to discover all available pages before exploring further.
northstar.init() API is designed for the common case: one long-lived session per process, runs created automatically by @northstar.trace, and a shared background worker. The low-level Northstar client gives you direct control over every layer of the hierarchy. Use it when you need to manage session boundaries explicitly, attach evaluation scores to individual runs, customize which event types are captured, or integrate NorthStar into a framework that manages its own execution lifecycle.
Instantiating the Client
endpoint parameter can be used instead of project_id for self-hosted deployments:
CaptureOptions
CaptureOptions controls which event types are actually written to the queue. All fields default to False when constructing the low-level client directly, giving you explicit opt-in control over what is stored.
Capture
USER_INPUT events — the initial message or prompt provided to the agent.Capture
SYSTEM_MESSAGE events from LLM request payloads.Capture
ASSISTANT_MESSAGE events — intermediate assistant responses within a conversation.Capture
REASONING events — model reasoning or chain-of-thought content when available.Capture
TOOL_ARGUMENTS events — the input arguments passed to each tool call.Capture
TOOL_RESULT events — the content returned by tool executions.Capture
FINAL_RESPONSE events — the terminal response delivered back to the user.northstar.init(), all seven flags are set to True automatically.
Full Low-Level Example
The following example demonstrates a complete run with user input, a tool span, a final response, and an attached evaluation score:Session, Run, and Span are context managers. Their __exit__ methods stamp ended_at, set the final status (ok or error), and enqueue the record for flushing. When the outermost session context exits, it calls client.flush() synchronously to drain the queue.Attaching Scores
client.score() attaches an evaluation score to any run. The score type is inferred from the Python type of value:
span_id=span.id.
Recording Run Events
TheRun object exposes typed recording methods that respect the CaptureOptions flags configured on the client:
| Method | Event type written |
|---|---|
run.record_user_input(content) | USER_INPUT |
run.record_system_message(content) | SYSTEM_MESSAGE |
run.record_assistant_message(content) | ASSISTANT_MESSAGE |
run.record_final_response(content) | FINAL_RESPONSE |
run.record_tool_result(content) | TOOL_RESULT |
run.record_custom_event(content) | CUSTOM |
run.record_error(exc) | sets status=ERROR and error field |
Session Lifecycle
Under the high-levelnorthstar.init() API, one session is created lazily the first time a @northstar.trace or with northstar.trace(...) block is opened. That session is reused for all subsequent traces in the same process. It is finalized (and its ended_at timestamp is set) when northstar.shutdown() is called — either explicitly or via the atexit hook registered by the SDK.
Under the low-level client, you control session boundaries entirely via with client.session(...) as session:. Multiple sessions can be opened sequentially; each session gets its own UUID and metadata.
Trace Replay
run.replay(tools=...) lets you re-execute a previously recorded run against a tool registry, replaying the exact tool call sequence deterministically:
Lifecycle and Threading
The low-levelNorthstar client does not start a background worker thread on its own. Flushing is triggered explicitly:
client.flush()— builds the current batch payload and POSTs it synchronously. Returns the payload dict. Clears all pending queues on success.client.aflush()— async variant offlush()for use inasynciocontexts.
_SDKState layer (used by northstar.init()) adds the background daemon thread. Its configuration parameters map directly to northstar.init() arguments:
| Parameter | Default | Description |
|---|---|---|
batch_size | 50 | Flush when the pending record count reaches this threshold |
flush_interval | 5.0 | Maximum seconds between background flushes |
max_queue_size | 1000 | Records beyond this limit are dropped with a debug warning |
daemon=True), so it does not prevent the Python interpreter from exiting. Call northstar.flush() explicitly at the end of short-lived scripts to ensure all queued data is sent before the process exits.
flush() and shutdown()
northstar.shutdown() is registered as an atexit handler automatically. It stops the background worker, finalizes the current session, and performs a final flush. You do not need to call it manually in most applications.