Skip to content

Commit 633f57b

Browse files
committed
Merge branch 'main' into smolagents-instrumentation
2 parents 2676c56 + d6c0537 commit 633f57b

288 files changed

Lines changed: 15085 additions & 19770 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/add-notebook-examples-to-docs.yml

Lines changed: 94 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ on:
66
- main
77
paths:
88
- 'examples/**'
9-
- 'docs/v1/examples/**'
10-
- '.github/workflows/add-notebook-examples-to-docs.yml'
11-
9+
- 'docs/v2/examples/**'
1210
workflow_dispatch:
1311

1412
permissions:
@@ -21,49 +19,114 @@ jobs:
2119
steps:
2220
- name: Checkout repository
2321
uses: actions/checkout@v3
22+
with:
23+
fetch-depth: 0
2424

2525
- name: Set up Python
2626
uses: actions/setup-python@v4
2727
with:
2828
python-version: '3.x'
2929

3030
- name: Install dependencies
31-
run: |
32-
pip install jupyter nbconvert
31+
run: pip install jupyter nbconvert
3332

34-
- name: Convert notebooks to markdown and add to docs
33+
- name: Detect and process notebooks
34+
id: process
3535
run: |
36-
set -x # Enable debug mode
37-
for file in docs/v1/examples/*.mdx; do
38-
echo "Processing file: $file"
39-
source_file=$(grep -oP '(?<=\{/\* SOURCE_FILE: ).*(?= \*/\})' "$file" || true)
40-
if [[ -z "$source_file" ]]; then
41-
continue
36+
# Determine comparison range
37+
case "${{ github.event_name }}" in
38+
"push")
39+
BASE_SHA="${{ github.event.before }}"
40+
[[ "$BASE_SHA" == "0000000000000000000000000000000000000000" ]] && BASE_SHA="$(git hash-object -t tree /dev/null)"
41+
HEAD_SHA="${{ github.event.after }}"
42+
;;
43+
"pull_request")
44+
BASE_SHA="${{ github.event.pull_request.base.sha }}"
45+
HEAD_SHA="${{ github.event.pull_request.head.sha }}"
46+
;;
47+
"workflow_dispatch")
48+
git fetch origin "${{ github.event.repository.default_branch }}" --depth=50
49+
BASE_SHA="origin/${{ github.event.repository.default_branch }}"
50+
HEAD_SHA="HEAD"
51+
;;
52+
*)
53+
exit 1
54+
;;
55+
esac
56+
57+
# Get changed files and filter in one pass
58+
CHANGED_FILES=$(git diff --name-only "$BASE_SHA" "$HEAD_SHA")
59+
60+
# Use arrays for better performance
61+
declare -A notebooks_set
62+
63+
# Process notebooks directly from changed files
64+
while IFS= read -r file; do
65+
if [[ "$file" =~ ^examples/.*\.ipynb$ ]]; then
66+
notebooks_set["$file"]=1
67+
elif [[ "$file" =~ ^docs/v2/examples/.*\.mdx$ ]] && [[ -f "$file" ]]; then
68+
# Extract source notebook from MDX file
69+
source_notebook=$(grep -oP '(?<=SOURCE_FILE: )[^ ]+' "$file" 2>/dev/null || true)
70+
if [[ -n "$source_notebook" && -f "$source_notebook" ]]; then
71+
notebooks_set["$source_notebook"]=1
72+
fi
4273
fi
43-
echo "Source file: $source_file"
44-
if [[ -f "$source_file" ]]; then
45-
echo "Converting notebook to markdown"
46-
jupyter nbconvert --to markdown "$source_file" || { echo "Error: Failed to convert $source_file" >&2; continue; }
47-
markdown_file="${source_file%.ipynb}.md"
48-
echo "Removing existing content after {/* SOURCE_FILE: ... */}"
49-
sed -i '\#{/\* SOURCE_FILE:#,$d' "$file"
50-
echo "Appending markdown to $file"
51-
echo -e "{/* SOURCE_FILE: $source_file */}\n" >> "$file"
52-
cat "$markdown_file" >> "$file" || { echo "Error: Failed to append markdown to $file" >&2; continue; }
53-
rm "$markdown_file" || { echo "Error: Failed to remove $markdown_file" >&2; continue; }
74+
done <<< "$CHANGED_FILES"
75+
76+
# Exit if no notebooks found
77+
[[ ${#notebooks_set[@]} -eq 0 ]] && exit 0
78+
79+
# Process each notebook and track results
80+
failed_count=0
81+
processed_notebooks=""
82+
for notebook in "${!notebooks_set[@]}"; do
83+
if python examples/generate_documentation.py "$notebook"; then
84+
processed_notebooks="$processed_notebooks$notebook"$'\n'
5485
else
55-
echo "Error: Source file not found: $source_file" >&2
86+
((failed_count++))
5687
fi
5788
done
89+
90+
[[ $failed_count -gt 0 ]] && exit 1
91+
92+
# Get modified files for PR description
93+
modified_files=$(git status --porcelain | grep -E '^\s*[AM]' | awk '{print $2}' | sort)
94+
95+
# Save outputs for PR
96+
echo "processed_notebooks<<EOF" >> $GITHUB_OUTPUT
97+
echo "$processed_notebooks" >> $GITHUB_OUTPUT
98+
echo "EOF" >> $GITHUB_OUTPUT
99+
100+
echo "modified_files<<EOF" >> $GITHUB_OUTPUT
101+
echo "$modified_files" >> $GITHUB_OUTPUT
102+
echo "EOF" >> $GITHUB_OUTPUT
58103
59104
- name: Create Pull Request
60105
uses: peter-evans/create-pull-request@v7
61106
with:
62-
committer: Howard Gil <howardbgil@gmail.com>
63-
commit-message: GitHub Action - Update examples in docs from notebooks
64-
title: GitHub Action - Update examples in docs from notebooks
65-
body: Changes detected in examples/** or docs/v1/examples/** triggered an update of the docs/v1/examples/**.mdx files to incorporate markdown from the corresponding notebook in examples/**.
66-
branch: update-examples-in-docs-from-notebooks
107+
token: ${{ secrets.GITHUB_TOKEN }}
108+
committer: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
109+
author: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
110+
commit-message: "docs: update examples from notebooks"
111+
title: "docs: update examples from notebooks"
112+
body: |
113+
Updates documentation examples from their source notebooks.
114+
115+
**Triggered by:** @${{ github.actor }}
116+
**Event:** ${{ github.event_name }}
117+
${{ steps.process.outputs.processed_notebooks && format('
118+
119+
## Processed Notebooks
120+
```
121+
{0}
122+
```', steps.process.outputs.processed_notebooks) || '' }}
123+
${{ steps.process.outputs.modified_files && format('
124+
125+
## Modified Files
126+
```
127+
{0}
128+
```', steps.process.outputs.modified_files) || '' }}
129+
branch: update-examples-docs
67130
delete-branch: true
68-
assignees: HowieG,siyangqiu,bboynton97,areibman
69-
reviewers: HowieG,siyangqiu,bboynton97,areibman
131+
assignees: the-praxs,bboynton97,areibman
132+
reviewers: the-praxs,bboynton97,areibman

.github/workflows/test-notebooks.yml

Lines changed: 0 additions & 103 deletions
This file was deleted.

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
<img src="https://img.shields.io/github/commit-activity/m/agentops-ai/agentops" alt="git commit activity">
1919
</a>
2020
<img src="https://img.shields.io/pypi/v/agentops?&color=3670A0" alt="PyPI - Version">
21+
<a href="https://github.com/AgentOps-AI/agentops-ts">
22+
<img src="https://img.shields.io/badge/TypeScript%20SDK-Available-blue?&color=3670A0" alt="TypeScript SDK">
23+
</a>
2124
<a href="https://opensource.org/licenses/MIT">
2225
<img src="https://img.shields.io/badge/License-MIT-yellow.svg?&color=3670A0" alt="License: MIT">
2326
</a>
@@ -219,7 +222,7 @@ Build multi-agent systems with tools, handoffs, and guardrails. AgentOps nativel
219222
pip install openai-agents
220223
```
221224

222-
- [AgentOps integration example](https://docs.agentops.ai/v1/integrations/agentssdk)
225+
- [AgentOps integration example](https://docs.agentops.ai/v1/integrations/agents_sdk)
223226
- [Official OpenAI Agents SDK documentation](https://openai.github.io/openai-agents-python/)
224227

225228
### CrewAI 🛶
@@ -777,7 +780,7 @@ from swarmzero import Agent, Swarm
777780
| ---------------------------------------------------------------------------- | ------------------------------------------ | -------------------------------------- |
778781
| ✅ Python SDK | ✅ Multi-session and Cross-session metrics | ✅ Custom eval metrics |
779782
| 🚧 Evaluation builder API | ✅ Custom event tag tracking | 🔜 Agent scorecards |
780-
| [Javascript/Typescript SDK](https://github.com/AgentOps-AI/agentops-node) | ✅ Session replays | 🔜 Evaluation playground + leaderboard |
783+
| 🚧 [Javascript/Typescript SDK (Alpha)](https://github.com/AgentOps-AI/agentops-node) | ✅ Session replays | 🔜 Evaluation playground + leaderboard |
781784

782785
## Debugging Roadmap 🧭
783786

agentops/__init__.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@
1515
from typing import List, Optional, Union, Dict, Any
1616
from agentops.client import Client
1717
from agentops.sdk.core import TraceContext, tracer
18-
from agentops.sdk.decorators import trace, session, agent, task, workflow, operation, tool
18+
from agentops.sdk.decorators import trace, session, agent, task, workflow, operation, tool, guardrail
1919
from agentops.enums import TraceState, SUCCESS, ERROR, UNSET
2020
from opentelemetry.trace.status import StatusCode
2121

2222
from agentops.logging.config import logger
23+
from agentops.helpers.deprecation import deprecated, warn_deprecated_param
2324
import threading
2425

2526
# Thread-safe client management
@@ -40,6 +41,7 @@ def get_client() -> Client:
4041
return _client
4142

4243

44+
@deprecated("Automatically tracked in v4.")
4345
def record(event):
4446
"""
4547
Legacy function to record an event. This is kept for backward compatibility.
@@ -107,6 +109,10 @@ def init(
107109
"""
108110
global _client
109111

112+
# Check for deprecated parameters and emit warnings
113+
if tags is not None:
114+
warn_deprecated_param("tags", "default_tags")
115+
110116
# Merge tags and default_tags if both are provided
111117
merged_tags = None
112118
if tags and default_tags:
@@ -116,6 +122,13 @@ def init(
116122
elif default_tags:
117123
merged_tags = default_tags
118124

125+
# Check if in a Jupyter Notebook (manual start/end_trace())
126+
try:
127+
get_ipython().__class__.__name__ == "ZMQInteractiveShell" # type: ignore
128+
auto_start_session = False
129+
except NameError:
130+
pass
131+
119132
# Prepare initialization arguments
120133
init_kwargs = {
121134
"api_key": api_key,
@@ -234,7 +247,7 @@ def end_trace(
234247
235248
Args:
236249
trace_context: The TraceContext object returned by start_trace. If None, ends all active traces.
237-
end_state: The final state of the trace (e.g., "Success", "Failure", "Error").
250+
end_state: The final state of the trace (e.g., "Success", "Indeterminate", "Error").
238251
"""
239252
if not tracer.initialized:
240253
logger.warning("AgentOps SDK not initialized. Cannot end trace.")
@@ -265,6 +278,7 @@ def end_trace(
265278
"task",
266279
"workflow",
267280
"operation",
281+
"guardrail",
268282
"tracer",
269283
"tool",
270284
# Trace state enums

agentops/client/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from .client import Client
2-
from .api import ApiClient
1+
from agentops.client.client import Client
2+
from agentops.client.api import ApiClient
33

44

55
__all__ = ["Client", "ApiClient"]

agentops/helpers/__init__.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
from .time import get_ISO_time, iso_to_unix_nano, from_unix_nano_to_iso
2-
from .serialization import (
1+
from agentops.helpers.time import get_ISO_time
2+
from agentops.helpers.serialization import (
33
AgentOpsJSONEncoder,
44
serialize_uuid,
55
safe_serialize,
66
is_jsonable,
77
filter_unjsonable,
88
)
9-
from .system import (
9+
from agentops.helpers.system import (
1010
get_host_env,
1111
get_sdk_details,
1212
get_os_details,
@@ -17,14 +17,11 @@
1717
get_current_directory,
1818
get_virtual_env,
1919
)
20-
from .version import get_agentops_version, check_agentops_update
21-
from .debug import debug_print_function_params
22-
from .env import get_env_bool, get_env_int, get_env_list
20+
from agentops.helpers.version import get_agentops_version, check_agentops_update
21+
from agentops.helpers.env import get_env_bool, get_env_int, get_env_list
2322

2423
__all__ = [
2524
"get_ISO_time",
26-
"iso_to_unix_nano",
27-
"from_unix_nano_to_iso",
2825
"AgentOpsJSONEncoder",
2926
"serialize_uuid",
3027
"safe_serialize",
@@ -41,7 +38,6 @@
4138
"get_virtual_env",
4239
"get_agentops_version",
4340
"check_agentops_update",
44-
"debug_print_function_params",
4541
"get_env_bool",
4642
"get_env_int",
4743
"get_env_list",

0 commit comments

Comments
 (0)