Skip to content

Commit adb72e9

Browse files
committed
feat(agentscope): support 2.x integration APIs
Add AgentScope 2.x agent and toolkit patch targets while preserving 1.x coverage. Update VCR-backed tests and auto-instrument smoke coverage for the new APIs.
1 parent 25de685 commit adb72e9

8 files changed

Lines changed: 314 additions & 91 deletions

File tree

py/noxfile.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,8 @@ def test_strands(session, version):
378378
@nox.session()
379379
@nox.parametrize("version", AGENTSCOPE_VERSIONS, ids=AGENTSCOPE_VERSIONS)
380380
def test_agentscope(session, version):
381+
if version == LATEST and sys.version_info < (3, 11):
382+
session.skip("AgentScope 2.x requires Python 3.11+")
381383
_install_test_deps(session)
382384
_install_matrix_dep(session, "agentscope", version)
383385
_install_group_locked(session, "test-agentscope")

py/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ latest = "agno==2.6.9"
351351
"2.1.0" = "agno==2.1.0"
352352

353353
[tool.braintrust.matrix.agentscope]
354-
latest = "agentscope==1.0.21"
354+
latest = "agentscope==2.0.0"
355355
"1.0.0" = "agentscope==1.0.0"
356356

357357
[tool.braintrust.matrix.autogen-agentchat]

py/src/braintrust/integrations/agentscope/cassettes/latest/test_auto_agentscope.yaml

Lines changed: 132 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
interactions:
22
- request:
33
body: '{"messages":[{"role":"system","name":"system","content":[{"type":"text","text":"You
4-
are a helpful assistant. Be brief."}]},{"role":"user","name":"user","content":[{"type":"text","text":"Say
5-
hi in two words."}]}],"model":"gpt-4o-mini","stream":true,"stream_options":{"include_usage":true},"temperature":0}'
4+
are a concise assistant. Answer in one sentence."}]},{"role":"user","name":"user","content":[{"type":"text","text":"Say
5+
hello in exactly two words."}]}],"model":"gpt-4o-mini","stream":false,"temperature":0}'
66
headers:
77
Accept:
88
- application/json
@@ -11,7 +11,7 @@ interactions:
1111
Connection:
1212
- keep-alive
1313
Content-Length:
14-
- '304'
14+
- '290'
1515
Content-Type:
1616
- application/json
1717
Host:
@@ -40,40 +40,136 @@ interactions:
4040
uri: https://api.openai.com/v1/chat/completions
4141
response:
4242
body:
43-
string: 'data: {"id":"chatcmpl-DX7NZBTmBc9FvHicZnqomTwNlJ2xI","object":"chat.completion.chunk","created":1776785561,"model":"gpt-4o-mini-2024-07-18","service_tier":"default","system_fingerprint":"fp_a7190374f3","choices":[{"index":0,"delta":{"role":"assistant","content":"","refusal":null},"logprobs":null,"finish_reason":null}],"usage":null,"obfuscation":"MSWgZo9n2"}
44-
45-
46-
data: {"id":"chatcmpl-DX7NZBTmBc9FvHicZnqomTwNlJ2xI","object":"chat.completion.chunk","created":1776785561,"model":"gpt-4o-mini-2024-07-18","service_tier":"default","system_fingerprint":"fp_a7190374f3","choices":[{"index":0,"delta":{"content":"Hello"},"logprobs":null,"finish_reason":null}],"usage":null,"obfuscation":"EYLOkE"}
47-
48-
49-
data: {"id":"chatcmpl-DX7NZBTmBc9FvHicZnqomTwNlJ2xI","object":"chat.completion.chunk","created":1776785561,"model":"gpt-4o-mini-2024-07-18","service_tier":"default","system_fingerprint":"fp_a7190374f3","choices":[{"index":0,"delta":{"content":"
50-
there"},"logprobs":null,"finish_reason":null}],"usage":null,"obfuscation":"OsMQm"}
51-
52-
53-
data: {"id":"chatcmpl-DX7NZBTmBc9FvHicZnqomTwNlJ2xI","object":"chat.completion.chunk","created":1776785561,"model":"gpt-4o-mini-2024-07-18","service_tier":"default","system_fingerprint":"fp_a7190374f3","choices":[{"index":0,"delta":{"content":"!"},"logprobs":null,"finish_reason":null}],"usage":null,"obfuscation":"LJrnGeP6qP"}
54-
55-
56-
data: {"id":"chatcmpl-DX7NZBTmBc9FvHicZnqomTwNlJ2xI","object":"chat.completion.chunk","created":1776785561,"model":"gpt-4o-mini-2024-07-18","service_tier":"default","system_fingerprint":"fp_a7190374f3","choices":[{"index":0,"delta":{},"logprobs":null,"finish_reason":"stop"}],"usage":null,"obfuscation":"0QFrc"}
57-
58-
59-
data: {"id":"chatcmpl-DX7NZBTmBc9FvHicZnqomTwNlJ2xI","object":"chat.completion.chunk","created":1776785561,"model":"gpt-4o-mini-2024-07-18","service_tier":"default","system_fingerprint":"fp_a7190374f3","choices":[],"usage":{"prompt_tokens":29,"completion_tokens":3,"total_tokens":32,"prompt_tokens_details":{"cached_tokens":0,"audio_tokens":0},"completion_tokens_details":{"reasoning_tokens":0,"audio_tokens":0,"accepted_prediction_tokens":0,"rejected_prediction_tokens":0}},"obfuscation":"3tj5TjOjSkh"}
60-
61-
62-
data: [DONE]
63-
64-
65-
'
43+
string: "{\n \"id\": \"chatcmpl-DX7NRqUSH6XKNRubUSWlhKnNmPNDB\",\n \"object\":
44+
\"chat.completion\",\n \"created\": 1776785553,\n \"model\": \"gpt-4o-mini-2024-07-18\",\n
45+
\ \"choices\": [\n {\n \"index\": 0,\n \"message\": {\n \"role\":
46+
\"assistant\",\n \"content\": \"Hello there!\",\n \"refusal\":
47+
null,\n \"annotations\": []\n },\n \"logprobs\": null,\n
48+
\ \"finish_reason\": \"stop\"\n }\n ],\n \"usage\": {\n \"prompt_tokens\":
49+
32,\n \"completion_tokens\": 3,\n \"total_tokens\": 35,\n \"prompt_tokens_details\":
50+
{\n \"cached_tokens\": 0,\n \"audio_tokens\": 0\n },\n \"completion_tokens_details\":
51+
{\n \"reasoning_tokens\": 0,\n \"audio_tokens\": 0,\n \"accepted_prediction_tokens\":
52+
0,\n \"rejected_prediction_tokens\": 0\n }\n },\n \"service_tier\":
53+
\"default\",\n \"system_fingerprint\": \"fp_6042092f77\"\n}\n"
6654
headers:
6755
CF-Cache-Status:
6856
- DYNAMIC
6957
CF-Ray:
70-
- 9efd715d39a53a03-YYZ
58+
- 9efd712b8cb878a5-YYZ
7159
Connection:
7260
- keep-alive
7361
Content-Type:
74-
- text/event-stream; charset=utf-8
62+
- application/json
63+
Date:
64+
- Tue, 21 Apr 2026 15:32:33 GMT
65+
Server:
66+
- cloudflare
67+
Strict-Transport-Security:
68+
- max-age=31536000; includeSubDomains; preload
69+
Transfer-Encoding:
70+
- chunked
71+
X-Content-Type-Options:
72+
- nosniff
73+
access-control-expose-headers:
74+
- X-Request-ID
75+
alt-svc:
76+
- h3=":443"; ma=86400
77+
content-length:
78+
- '818'
79+
openai-organization:
80+
- braintrust-data
81+
openai-processing-ms:
82+
- '303'
83+
openai-project:
84+
- proj_vsCSXafhhByzWOThMrJcZiw9
85+
openai-version:
86+
- '2020-10-01'
87+
set-cookie:
88+
- __cf_bm=vWZsqZxXqzK8jjN5seiu2E8BqryLRFNDYMLsGe_TiUQ-1776785553.2100453-1.0.1.1-jpJ.lEurU5WQQfPpsQ0nN6um.4nJttOu7.z79GA17wHU4ttEm4thC0lQws5XBcsmd95Y8H1r04sdMK4BboF_gKPQUBii3cJy1DzHoD4mGyzEG6boSWTr4toKmbv1ynts;
89+
HttpOnly; Secure; Path=/; Domain=api.openai.com; Expires=Tue, 21 Apr 2026
90+
16:02:33 GMT
91+
x-openai-proxy-wasm:
92+
- v0.1
93+
x-ratelimit-limit-requests:
94+
- '30000'
95+
x-ratelimit-limit-tokens:
96+
- '150000000'
97+
x-ratelimit-remaining-requests:
98+
- '29999'
99+
x-ratelimit-remaining-tokens:
100+
- '149999975'
101+
x-ratelimit-reset-requests:
102+
- 2ms
103+
x-ratelimit-reset-tokens:
104+
- 0s
105+
x-request-id:
106+
- req_249eb93d6eb44d4788eac0bc583d79de
107+
status:
108+
code: 200
109+
message: OK
110+
- request:
111+
body: '{"messages":[{"role":"system","name":"system","content":[{"type":"text","text":"You
112+
are a concise assistant. Answer in one sentence."}]},{"role":"user","name":"user","content":[{"type":"text","text":"Say
113+
hello in exactly two words."}]}],"model":"gpt-4o-mini","stream":false,"temperature":0}'
114+
headers:
115+
Accept:
116+
- application/json
117+
Accept-Encoding:
118+
- gzip, deflate
119+
Connection:
120+
- keep-alive
121+
Content-Length:
122+
- '290'
123+
Content-Type:
124+
- application/json
125+
Host:
126+
- api.openai.com
127+
User-Agent:
128+
- AsyncOpenAI/Python 2.31.0
129+
X-Stainless-Arch:
130+
- arm64
131+
X-Stainless-Async:
132+
- async:asyncio
133+
X-Stainless-Lang:
134+
- python
135+
X-Stainless-OS:
136+
- MacOS
137+
X-Stainless-Package-Version:
138+
- 2.31.0
139+
X-Stainless-Runtime:
140+
- CPython
141+
X-Stainless-Runtime-Version:
142+
- 3.14.3
143+
x-stainless-read-timeout:
144+
- '600'
145+
x-stainless-retry-count:
146+
- '0'
147+
method: POST
148+
uri: https://api.openai.com/v1/chat/completions
149+
response:
150+
body:
151+
string: "{\n \"id\": \"chatcmpl-DX7O3zfeUJOH15DVkUmgReCpkVZxE\",\n \"object\":
152+
\"chat.completion\",\n \"created\": 1776785591,\n \"model\": \"gpt-4o-mini-2024-07-18\",\n
153+
\ \"choices\": [\n {\n \"index\": 0,\n \"message\": {\n \"role\":
154+
\"assistant\",\n \"content\": \"Hello there.\",\n \"refusal\":
155+
null,\n \"annotations\": []\n },\n \"logprobs\": null,\n
156+
\ \"finish_reason\": \"stop\"\n }\n ],\n \"usage\": {\n \"prompt_tokens\":
157+
32,\n \"completion_tokens\": 3,\n \"total_tokens\": 35,\n \"prompt_tokens_details\":
158+
{\n \"cached_tokens\": 0,\n \"audio_tokens\": 0\n },\n \"completion_tokens_details\":
159+
{\n \"reasoning_tokens\": 0,\n \"audio_tokens\": 0,\n \"accepted_prediction_tokens\":
160+
0,\n \"rejected_prediction_tokens\": 0\n }\n },\n \"service_tier\":
161+
\"default\",\n \"system_fingerprint\": \"fp_6042092f77\"\n}\n"
162+
headers:
163+
CF-Cache-Status:
164+
- DYNAMIC
165+
CF-Ray:
166+
- 9efd721b1877964a-YYZ
167+
Connection:
168+
- keep-alive
169+
Content-Type:
170+
- application/json
75171
Date:
76-
- Tue, 21 Apr 2026 15:32:41 GMT
172+
- Tue, 21 Apr 2026 15:33:11 GMT
77173
Server:
78174
- cloudflare
79175
Strict-Transport-Security:
@@ -86,18 +182,20 @@ interactions:
86182
- X-Request-ID
87183
alt-svc:
88184
- h3=":443"; ma=86400
185+
content-length:
186+
- '818'
89187
openai-organization:
90188
- braintrust-data
91189
openai-processing-ms:
92-
- '154'
190+
- '364'
93191
openai-project:
94192
- proj_vsCSXafhhByzWOThMrJcZiw9
95193
openai-version:
96194
- '2020-10-01'
97195
set-cookie:
98-
- __cf_bm=PZv8LQidJAxjTDU4p9DA3ZPYHiXPGPyY_yhofay0BKY-1776785561.160069-1.0.1.1-GtP3HMxTLMRVoqZ.qRVYzRiP9D5xXLeNSfYc2L1uh17sfJU_JDi2C9GtNL8_WuOaaAuEjRvjpPzcLBZcbrY7zDtljrRC0NkG.74n4YLisUDTBu06g9VJdZ6OyV4Pm.kl;
196+
- __cf_bm=0gBwjzu6S8NGJOZz8DHRfVPsaoNL7ANqedT8QLla.yg-1776785591.536904-1.0.1.1-8DZ8d3JNr0lAQVcDW_i1puCgA6zGjTDBjyq.9ZvoVuNK_ag_QIUapir9HQ0pbs6dOeD.7gMY9LWxtPR_K3mVM4jsFdH5p9pye0F0AXwbEYueTCwD4n9ncXY9D2TH4daa;
99197
HttpOnly; Secure; Path=/; Domain=api.openai.com; Expires=Tue, 21 Apr 2026
100-
16:02:41 GMT
198+
16:03:11 GMT
101199
x-openai-proxy-wasm:
102200
- v0.1
103201
x-ratelimit-limit-requests:
@@ -107,13 +205,13 @@ interactions:
107205
x-ratelimit-remaining-requests:
108206
- '29999'
109207
x-ratelimit-remaining-tokens:
110-
- '149999980'
208+
- '149999975'
111209
x-ratelimit-reset-requests:
112210
- 2ms
113211
x-ratelimit-reset-tokens:
114212
- 0s
115213
x-request-id:
116-
- req_647b1639b38341d79da968edc2bff915
214+
- req_1e92a22c0c334c628bcaf2941ab2d3ba
117215
status:
118216
code: 200
119217
message: OK

py/src/braintrust/integrations/agentscope/integration.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44

55
from .patchers import (
66
AgentCallPatcher,
7+
AgentReplyPatcher,
78
ChatModelPatcher,
89
FanoutPipelinePatcher,
910
SequentialPipelinePatcher,
1011
ToolkitCallToolFunctionPatcher,
12+
ToolkitCallToolPatcher,
1113
)
1214

1315

@@ -19,8 +21,10 @@ class AgentScopeIntegration(BaseIntegration):
1921
min_version = "1.0.0"
2022
patchers = (
2123
AgentCallPatcher,
24+
AgentReplyPatcher,
2225
SequentialPipelinePatcher,
2326
FanoutPipelinePatcher,
2427
ToolkitCallToolFunctionPatcher,
28+
ToolkitCallToolPatcher,
2529
ChatModelPatcher,
2630
)

py/src/braintrust/integrations/agentscope/patchers.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,23 @@
1212

1313

1414
class AgentCallPatcher(FunctionWrapperPatcher):
15-
"""Patch AgentScope agent execution."""
15+
"""Patch AgentScope 1.x agent execution."""
1616

1717
name = "agentscope.agent.call"
1818
target_module = "agentscope.agent"
1919
target_path = "AgentBase.__call__"
2020
wrapper = _agent_call_wrapper
2121

2222

23+
class AgentReplyPatcher(FunctionWrapperPatcher):
24+
"""Patch AgentScope 2.x agent execution."""
25+
26+
name = "agentscope.agent.reply"
27+
target_module = "agentscope.agent"
28+
target_path = "Agent.reply"
29+
wrapper = _agent_call_wrapper
30+
31+
2332
class SequentialPipelinePatcher(FunctionWrapperPatcher):
2433
"""Patch AgentScope sequential pipeline execution."""
2534

@@ -39,14 +48,23 @@ class FanoutPipelinePatcher(FunctionWrapperPatcher):
3948

4049

4150
class ToolkitCallToolFunctionPatcher(FunctionWrapperPatcher):
42-
"""Patch AgentScope toolkit execution."""
51+
"""Patch AgentScope 1.x toolkit execution."""
4352

4453
name = "agentscope.tool.call_tool_function"
4554
target_module = "agentscope.tool"
4655
target_path = "Toolkit.call_tool_function"
4756
wrapper = _toolkit_call_tool_function_wrapper
4857

4958

59+
class ToolkitCallToolPatcher(FunctionWrapperPatcher):
60+
"""Patch AgentScope 2.x toolkit execution."""
61+
62+
name = "agentscope.tool.call_tool"
63+
target_module = "agentscope.tool"
64+
target_path = "Toolkit.call_tool"
65+
wrapper = _toolkit_call_tool_function_wrapper
66+
67+
5068
class _OpenAIChatModelPatcher(FunctionWrapperPatcher):
5169
name = "agentscope.model.openai"
5270
target_module = "agentscope.model"

0 commit comments

Comments
 (0)