AgentFlare class
The main entry point for the SDK — configure once, use everywhere.
Constructor
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
api_key | str | Yes | — | Your AgentFlare API key (starts with ag_). Found in the dashboard. |
agent_id | str | Yes | — | Unique identifier for this agent. All events and costs are grouped by this ID. |
backend_url | str | No | AgentFlare hosted backend | URL of the AgentFlare backend. Only set this when self-hosting. |
cost_threshold | float | No | None | Daily spend limit in USD. If set, automatically registers the threshold with the backend on startup. |
slack_webhook | str | No | None | Slack incoming webhook URL. If set, a message is sent when the agent is auto-paused. |
Methods
send_event(event: AgentEvent) → bool
Sends one event to the backend. Returns True if the agent is still alive, False if it has been paused (either by threshold or manually).
Important: When send_event returns False, it also sets the internal _paused flag. All subsequent calls to send_event will immediately return False without making a network request, so it's safe to call this in a tight loop.
is_paused (property)
Returns True if the agent has been paused (either detected via send_event or set externally).
callback (property)
Returns an AgentFlareCallback instance bound to this tracker. Use this with LangChain chains.
track(fn) (decorator)
Wraps a function to automatically emit agent_start and agent_end events. See the decorator docs.
How the pause flag works
When AgentFlare pauses your agent, it's a two-step process:
- The backend sets
is_paused = truein Supabase for youragent_id. - The SDK receives
"paused": truein the nextsend_eventresponse and caches it locally as_paused = True.
Once _paused is True, the SDK short-circuits all future send_event calls — it returns False immediately without a network hop. This means even if your agent has many LLM calls queued up, they all get blocked quickly after a pause is registered.
The _paused flag is in-memory only. It resets when you create a new AgentFlare instance (e.g. on the next run of your agent). If the agent was paused in Supabase but your code restarts, the flag will be re-detected on the first send_event call.