Skip to content

Python SDK for AI agent monitoring, LLM cost tracking, benchmarking, and more. Integrates with most LLMs and agent frameworks including CrewAI, Agno, OpenAI Agents SDK, Langchain, Autogen, AG2, and CamelAI

terminal logs in jupyter notebooks (#1049)

koreandinnera61baa6d1321
diff --git a/agentops/__init__.py b/agentops/__init__.py
index 2f10c142..e4d48055 100755
--- a/agentops/__init__.py
+++ b/agentops/__init__.py
@@ -116,6 +116,13 @@ def init(
elif default_tags:
merged_tags = default_tags
+ # Check if in a Jupyter Notebook (manual start/end_trace())
+ try:
+ get_ipython().__class__.__name__ == "ZMQInteractiveShell" # type: ignore
+ auto_start_session = False
+ except NameError:
+ pass
+
# Prepare initialization arguments
init_kwargs = {
"api_key": api_key,
diff --git a/agentops/instrumentation/__init__.py b/agentops/instrumentation/__init__.py
index cb4a6b88..86740a62 100644
--- a/agentops/instrumentation/__init__.py
+++ b/agentops/instrumentation/__init__.py
@@ -35,7 +35,6 @@ from opentelemetry.instrumentation.instrumentor import BaseInstrumentor # type:
from agentops.logging import logger
from agentops.sdk.core import tracer
-
# Module-level state variables
_active_instrumentors: list[BaseInstrumentor] = []
_original_builtins_import = builtins.__import__ # Store original import
diff --git a/docs/v2/usage/sdk-reference.mdx b/docs/v2/usage/sdk-reference.mdx
index bfb1d65f..9d4812d2 100644
--- a/docs/v2/usage/sdk-reference.mdx
+++ b/docs/v2/usage/sdk-reference.mdx
@@ -29,7 +29,7 @@ Initializes the AgentOps SDK and automatically starts tracking your application.
- `default_tags` (List[str], optional): Default tags for the sessions that can be used for grouping or sorting later (e.g. ["GPT-4"]).
- `tags` (List[str], optional): [Deprecated] Use `default_tags` instead.
- `instrument_llm_calls` (bool, optional): Whether to instrument LLM calls automatically. Defaults to True.
-- `auto_start_session` (bool, optional): Whether to start a session automatically when the client is created. Defaults to True.
+- `auto_start_session` (bool, optional): Whether to start a session automatically when the client is created. Set to False if running in a Jupyter Notebook. Defaults to True.
- `auto_init` (bool, optional): Whether to automatically initialize the client on import. Defaults to True.
- `skip_auto_end_session` (bool, optional): Don't automatically end session based on your framework's decision-making. Defaults to False.
- `env_data_opt_out` (bool, optional): Whether to opt out of collecting environment data. Defaults to False.
diff --git a/examples/openai_agents/customer_service_agent.ipynb b/examples/openai_agents/customer_service_agent.ipynb
index 6135c44d..1485d3ee 100644
--- a/examples/openai_agents/customer_service_agent.ipynb
+++ b/examples/openai_agents/customer_service_agent.ipynb
@@ -96,7 +96,7 @@
"metadata": {},
"outputs": [],
"source": [
- "agentops.init(tags=[\"customer-service-agent\", \"openai-agents\", \"agentops-example\"], auto_start_session=False)\n",
+ "agentops.init(tags=[\"customer-service-agent\", \"openai-agents\", \"agentops-example\"])\n",
"tracer = agentops.start_trace(trace_name=\"Customer Service Agent\")"
]
},