Skip to content

Commit a61baa6

Browse files
terminal logs in jupyter notebooks (#1049)
* init() sets auto_start_session to false if in notebook and changed docs * deal with non-notebook manual trace * ruff, if you will * ruff redux * ruff redux 2 * fix ruff deletion --------- Co-authored-by: Pratyush Shukla <[email protected]>
1 parent eb34e26 commit a61baa6

File tree

4 files changed

+9
-3
lines changed

4 files changed

+9
-3
lines changed

agentops/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,13 @@ def init(
116116
elif default_tags:
117117
merged_tags = default_tags
118118

119+
# Check if in a Jupyter Notebook (manual start/end_trace())
120+
try:
121+
get_ipython().__class__.__name__ == "ZMQInteractiveShell" # type: ignore
122+
auto_start_session = False
123+
except NameError:
124+
pass
125+
119126
# Prepare initialization arguments
120127
init_kwargs = {
121128
"api_key": api_key,

agentops/instrumentation/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
from agentops.logging import logger
3636
from agentops.sdk.core import tracer
3737

38-
3938
# Module-level state variables
4039
_active_instrumentors: list[BaseInstrumentor] = []
4140
_original_builtins_import = builtins.__import__ # Store original import

docs/v2/usage/sdk-reference.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Initializes the AgentOps SDK and automatically starts tracking your application.
2929
- `default_tags` (List[str], optional): Default tags for the sessions that can be used for grouping or sorting later (e.g. ["GPT-4"]).
3030
- `tags` (List[str], optional): [Deprecated] Use `default_tags` instead.
3131
- `instrument_llm_calls` (bool, optional): Whether to instrument LLM calls automatically. Defaults to True.
32-
- `auto_start_session` (bool, optional): Whether to start a session automatically when the client is created. Defaults to True.
32+
- `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.
3333
- `auto_init` (bool, optional): Whether to automatically initialize the client on import. Defaults to True.
3434
- `skip_auto_end_session` (bool, optional): Don't automatically end session based on your framework's decision-making. Defaults to False.
3535
- `env_data_opt_out` (bool, optional): Whether to opt out of collecting environment data. Defaults to False.

examples/openai_agents/customer_service_agent.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
"metadata": {},
9797
"outputs": [],
9898
"source": [
99-
"agentops.init(tags=[\"customer-service-agent\", \"openai-agents\", \"agentops-example\"], auto_start_session=False)\n",
99+
"agentops.init(tags=[\"customer-service-agent\", \"openai-agents\", \"agentops-example\"])\n",
100100
"tracer = agentops.start_trace(trace_name=\"Customer Service Agent\")"
101101
]
102102
},

0 commit comments

Comments
 (0)