Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.agentbasis.co/llms.txt

Use this file to discover all available pages before exploring further.

This page lists all public functions exported by the AgentBasis SDK.

agentbasis

Core module functions imported directly from agentbasis.
import agentbasis

Initialization

FunctionDescription
init(api_key: str = None, agent_id: str = None) -> AgentBasisInitialize the SDK. Reads from AGENTBASIS_API_KEY and AGENTBASIS_AGENT_ID env vars if not provided.
flush(timeout_millis: int = 30000) -> boolForce flush all pending telemetry data. Returns True if successful.
shutdown() -> NoneShut down the SDK and flush pending data. Auto-called on exit.

Context Management

FunctionDescription
set_user(user_id: str | None) -> NoneSet the current user ID globally.
set_session(session_id: str | None) -> NoneSet the current session ID globally.
set_conversation(conversation_id: str | None) -> NoneSet the current conversation ID globally.
set_metadata(metadata: dict | None) -> NoneSet custom metadata globally (e.g., {"plan": "pro"}).
get_user() -> str | NoneGet the current user ID.
get_session() -> str | NoneGet the current session ID.
get_conversation() -> str | NoneGet the current conversation ID.
get_metadata() -> dict | NoneGet the current metadata.

Context Managers & Decorators

FunctionDescription
context(user_id, session_id, conversation_id, metadata)Context manager for scoped context.
with_context(user_id, session_id, conversation_id, metadata)Decorator for setting context on a function.
traceDecorator to track function execution as a span. Works with sync and async.

agentbasis.llms.openai

from agentbasis.llms.openai import instrument
FunctionDescription
instrument() -> NoneAuto-instrument OpenAI SDK. Traces both OpenAI and AsyncOpenAI clients.

agentbasis.llms.anthropic

from agentbasis.llms.anthropic import instrument
FunctionDescription
instrument() -> NoneAuto-instrument Anthropic SDK. Traces both Anthropic and AsyncAnthropic clients.

agentbasis.llms.gemini

from agentbasis.llms.gemini import instrument
FunctionDescription
instrument() -> NoneAuto-instrument Google Gemini SDK. Traces GenerativeModel.generate_content() sync and async.

agentbasis.frameworks.langchain

from agentbasis.frameworks.langchain import get_callback_handler, instrument, get_callback_config
FunctionDescription
get_callback_handler() -> AgentBasisCallbackHandlerGet a new callback handler instance.
instrument() -> AgentBasisCallbackHandlerGet the global singleton callback handler.
get_callback_config() -> dictGet a RunnableConfig dict with callbacks pre-configured.

AgentBasisCallbackHandler

Callback handler that traces:
  • LLM calls (on_llm_start/end/error)
  • Chain execution (on_chain_start/end/error)
  • Tool invocations (on_tool_start/end/error)
  • Retriever operations (on_retriever_start/end/error)

agentbasis.frameworks.pydanticai

from agentbasis.frameworks.pydanticai import instrument, get_instrumentation_settings, get_metadata_callback, create_traced_agent
FunctionDescription
instrument(include_content: bool = True, include_binary_content: bool = False) -> NoneEnable global instrumentation for all Pydantic AI agents.
get_instrumentation_settings(include_content, include_binary_content) -> InstrumentationSettingsGet settings for per-agent instrumentation.
get_metadata_callback() -> CallableGet a callback that injects AgentBasis context into traces.
create_traced_agent(model: str, include_content: bool = True, **kwargs) -> AgentCreate a Pydantic AI agent pre-configured with tracing.

Parameters

ParameterDescription
include_contentWhether to log prompts and completions. Set False for privacy. Default: True
include_binary_contentWhether to include binary content like images. Default: False