redberry-sdk 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. redberry_sdk-0.1.0/LICENSE +202 -0
  2. redberry_sdk-0.1.0/NOTICE +4 -0
  3. redberry_sdk-0.1.0/PKG-INFO +157 -0
  4. redberry_sdk-0.1.0/README.md +86 -0
  5. redberry_sdk-0.1.0/pyproject.toml +96 -0
  6. redberry_sdk-0.1.0/setup.cfg +4 -0
  7. redberry_sdk-0.1.0/src/redberry_sdk/__init__.py +20 -0
  8. redberry_sdk-0.1.0/src/redberry_sdk/_call_role.py +78 -0
  9. redberry_sdk-0.1.0/src/redberry_sdk/_config.py +181 -0
  10. redberry_sdk-0.1.0/src/redberry_sdk/_coverage.py +70 -0
  11. redberry_sdk-0.1.0/src/redberry_sdk/_emit.py +541 -0
  12. redberry_sdk-0.1.0/src/redberry_sdk/_emit_aws.py +254 -0
  13. redberry_sdk-0.1.0/src/redberry_sdk/_emit_azure.py +214 -0
  14. redberry_sdk-0.1.0/src/redberry_sdk/_env.py +20 -0
  15. redberry_sdk-0.1.0/src/redberry_sdk/_sdk.py +364 -0
  16. redberry_sdk-0.1.0/src/redberry_sdk/_span_event_logger.py +96 -0
  17. redberry_sdk-0.1.0/src/redberry_sdk/_version.py +3 -0
  18. redberry_sdk-0.1.0/src/redberry_sdk/hasher/__init__.py +115 -0
  19. redberry_sdk-0.1.0/src/redberry_sdk/hasher/_agents.py +62 -0
  20. redberry_sdk-0.1.0/src/redberry_sdk/hasher/_azure.py +396 -0
  21. redberry_sdk-0.1.0/src/redberry_sdk/hasher/_canonical.py +156 -0
  22. redberry_sdk-0.1.0/src/redberry_sdk/hasher/_config.py +165 -0
  23. redberry_sdk-0.1.0/src/redberry_sdk/hasher/_crypto.py +88 -0
  24. redberry_sdk-0.1.0/src/redberry_sdk/hasher/_envelope.py +84 -0
  25. redberry_sdk-0.1.0/src/redberry_sdk/hasher/_http.py +134 -0
  26. redberry_sdk-0.1.0/src/redberry_sdk/hasher/_processor.py +381 -0
  27. redberry_sdk-0.1.0/src/redberry_sdk/hasher/_report.py +143 -0
  28. redberry_sdk-0.1.0/src/redberry_sdk/hasher/_sigv4.py +132 -0
  29. redberry_sdk-0.1.0/src/redberry_sdk/hasher/_span.py +101 -0
  30. redberry_sdk-0.1.0/src/redberry_sdk/hasher/stores.py +586 -0
  31. redberry_sdk-0.1.0/src/redberry_sdk/instrumentors/__init__.py +236 -0
  32. redberry_sdk-0.1.0/src/redberry_sdk/instrumentors/_base.py +77 -0
  33. redberry_sdk-0.1.0/src/redberry_sdk/instrumentors/_expected.py +202 -0
  34. redberry_sdk-0.1.0/src/redberry_sdk/instrumentors/_native.py +97 -0
  35. redberry_sdk-0.1.0/src/redberry_sdk/instrumentors/_request_snapshot.py +449 -0
  36. redberry_sdk-0.1.0/src/redberry_sdk/instrumentors/_stream_capture.py +363 -0
  37. redberry_sdk-0.1.0/src/redberry_sdk/instrumentors/_tool_definitions.py +403 -0
  38. redberry_sdk-0.1.0/src/redberry_sdk/instrumentors/_wrapt_fallback.py +155 -0
  39. redberry_sdk-0.1.0/src/redberry_sdk/integrations/__init__.py +1 -0
  40. redberry_sdk-0.1.0/src/redberry_sdk/integrations/openai_agents.py +450 -0
  41. redberry_sdk-0.1.0/src/redberry_sdk/valp.py +536 -0
  42. redberry_sdk-0.1.0/src/redberry_sdk.egg-info/PKG-INFO +157 -0
  43. redberry_sdk-0.1.0/src/redberry_sdk.egg-info/SOURCES.txt +44 -0
  44. redberry_sdk-0.1.0/src/redberry_sdk.egg-info/dependency_links.txt +1 -0
  45. redberry_sdk-0.1.0/src/redberry_sdk.egg-info/requires.txt +55 -0
  46. redberry_sdk-0.1.0/src/redberry_sdk.egg-info/top_level.txt +1 -0
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,4 @@
1
+ redberry-sdk
2
+ Copyright 2026 Redberry Labs
3
+
4
+ This product includes software developed at Redberry Labs (https://redberrylabs.com).
@@ -0,0 +1,157 @@
1
+ Metadata-Version: 2.4
2
+ Name: redberry-sdk
3
+ Version: 0.1.0
4
+ Summary: Records an AI agent's model and tool calls with OpenTelemetry and sends them to the customer's Redberry install.
5
+ Author: Redberry Labs
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/RedberryLabs/redberry-python
8
+ Project-URL: Source, https://github.com/RedberryLabs/redberry-python
9
+ Project-URL: Changelog, https://github.com/RedberryLabs/redberry-python/blob/main/CHANGELOG.md
10
+ Keywords: opentelemetry,ai agents,llm,observability,redberry
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Topic :: System :: Monitoring
18
+ Requires-Python: >=3.11
19
+ Description-Content-Type: text/markdown
20
+ License-File: LICENSE
21
+ License-File: NOTICE
22
+ Requires-Dist: opentelemetry-api>=1.27
23
+ Requires-Dist: opentelemetry-sdk>=1.27
24
+ Requires-Dist: opentelemetry-exporter-otlp-proto-grpc>=1.27
25
+ Requires-Dist: opentelemetry-exporter-otlp-proto-http>=1.27
26
+ Requires-Dist: requests>=2.31
27
+ Requires-Dist: wrapt>=1.16
28
+ Requires-Dist: pydantic>=2.7
29
+ Requires-Dist: pyyaml>=6.0
30
+ Requires-Dist: python-dotenv>=1.0
31
+ Provides-Extra: providers
32
+ Requires-Dist: opentelemetry-instrumentation-openai-v2<2.4,>=2.0b0; extra == "providers"
33
+ Requires-Dist: httpx>=0.27; extra == "providers"
34
+ Requires-Dist: wrapt<2,>=1.17; extra == "providers"
35
+ Requires-Dist: openinference-instrumentation-anthropic>=0.1; extra == "providers"
36
+ Requires-Dist: opentelemetry-instrumentation-bedrock>=0.60; extra == "providers"
37
+ Requires-Dist: opentelemetry-instrumentation-cohere>=0.60; extra == "providers"
38
+ Requires-Dist: opentelemetry-instrumentation-mistralai>=0.60; extra == "providers"
39
+ Requires-Dist: opentelemetry-instrumentation-ollama>=0.60; extra == "providers"
40
+ Requires-Dist: opentelemetry-instrumentation-vertexai>=0.60; extra == "providers"
41
+ Requires-Dist: opentelemetry-instrumentation-google-generativeai>=0.60; extra == "providers"
42
+ Requires-Dist: openinference-instrumentation-google-genai>=1.4; extra == "providers"
43
+ Requires-Dist: opentelemetry-instrumentation-groq>=0.60; extra == "providers"
44
+ Requires-Dist: opentelemetry-instrumentation-together>=0.60; extra == "providers"
45
+ Requires-Dist: opentelemetry-instrumentation-replicate>=0.60; extra == "providers"
46
+ Provides-Extra: frameworks
47
+ Requires-Dist: opentelemetry-instrumentation-langchain>=0.1; extra == "frameworks"
48
+ Requires-Dist: opentelemetry-instrumentation-llamaindex>=0.60; extra == "frameworks"
49
+ Requires-Dist: opentelemetry-instrumentation-crewai>=0.60; extra == "frameworks"
50
+ Requires-Dist: opentelemetry-instrumentation-haystack>=0.60; extra == "frameworks"
51
+ Requires-Dist: openinference-instrumentation-openai-agents<2.6,>=2.0; extra == "frameworks"
52
+ Provides-Extra: vectordb
53
+ Requires-Dist: opentelemetry-instrumentation-chromadb>=0.60; extra == "vectordb"
54
+ Requires-Dist: opentelemetry-instrumentation-pinecone>=0.60; extra == "vectordb"
55
+ Requires-Dist: opentelemetry-instrumentation-qdrant>=0.60; extra == "vectordb"
56
+ Requires-Dist: opentelemetry-instrumentation-weaviate>=0.60; extra == "vectordb"
57
+ Provides-Extra: openai-agents
58
+ Requires-Dist: openai-agents>=0.22; extra == "openai-agents"
59
+ Provides-Extra: hasher
60
+ Requires-Dist: cryptography>=42; extra == "hasher"
61
+ Provides-Extra: all
62
+ Requires-Dist: redberry-sdk[frameworks,providers,vectordb]; extra == "all"
63
+ Provides-Extra: dev
64
+ Requires-Dist: cryptography>=42; extra == "dev"
65
+ Requires-Dist: pytest>=8.0; extra == "dev"
66
+ Requires-Dist: pytest-asyncio>=0.24; extra == "dev"
67
+ Requires-Dist: httpx>=0.27; extra == "dev"
68
+ Requires-Dist: respx>=0.21; extra == "dev"
69
+ Requires-Dist: ruff>=0.6; extra == "dev"
70
+ Dynamic: license-file
71
+
72
+ # redberry-sdk
73
+
74
+ Records an AI agent's model and tool calls with OpenTelemetry and sends them to the customer's own Redberry
75
+ install. Redberry uses these records to keep a tamper-evident evidence chain for each agent and to price its risk.
76
+
77
+ The SDK sends only to the Redberry install in your own cloud account (or to an endpoint you set). It does not
78
+ send anything to Redberry directly.
79
+
80
+ ## Install
81
+
82
+ ```bash
83
+ pip install redberry-sdk # core
84
+ pip install "redberry-sdk[providers]" # plus instrumentation for model providers (OpenAI, Anthropic, ...)
85
+ pip install "redberry-sdk[all]" # providers, agent frameworks and vector databases
86
+ ```
87
+
88
+ Python 3.11 or later.
89
+
90
+ | Extra | Installs instrumentation for |
91
+ |---|---|
92
+ | `providers` | OpenAI, Anthropic, Amazon Bedrock, Cohere, Mistral, Ollama, Vertex AI, Google GenAI, Groq, Together, Replicate |
93
+ | `frameworks` | LangChain, LlamaIndex, CrewAI, Haystack, OpenAI Agents SDK |
94
+ | `vectordb` | Chroma, Pinecone, Qdrant, Weaviate |
95
+ | `openai-agents` | the OpenAI Agents SDK itself, for its `valp.*` integration |
96
+ | `hasher` | the optional per-run signing path |
97
+
98
+ ## Quick start
99
+
100
+ ```python
101
+ import redberry_sdk
102
+
103
+ redberry_sdk.init(agent="refund-agent") # your agent's name, as you will approve it in the Redberry portal
104
+ ```
105
+
106
+ Call `init()` once, before the agent makes its first model call. Model calls made through supported libraries are
107
+ then recorded automatically.
108
+
109
+ **Serverless functions** (AWS Lambda, Azure Functions, Cloud Run functions) can be frozen as soon as a request
110
+ returns. Flush before returning:
111
+
112
+ ```python
113
+ @redberry_sdk.flush_after
114
+ def handler(event, context):
115
+ ...
116
+ ```
117
+
118
+ or call `redberry_sdk.flush()` yourself.
119
+
120
+ **Temperature.** Redberry prices an agent from its sampled behaviour, so the agent's model calls must run at
121
+ temperature 1.0.
122
+
123
+ ## Where records go
124
+
125
+ On these platforms the SDK finds your install automatically and authenticates with the platform's own identity;
126
+ no keys are needed:
127
+
128
+ | Platform | How the install is found | Authentication |
129
+ |---|---|---|
130
+ | Google Cloud (Cloud Run services, jobs, functions) | the install in the same project | the service account's ID token |
131
+ | AWS (Lambda, ECS) | `s3://redberry-<account>-<region>/ingest.json` | AWS Signature Version 4 with the role's credentials |
132
+ | Azure (Functions, Container Apps) | the Redberry API, by the managed identity | the managed identity's Entra ID token |
133
+
134
+ Elsewhere, set the ingest address explicitly.
135
+
136
+ | Environment variable | Meaning |
137
+ |---|---|
138
+ | `REDBERRY_INGEST_URL` | the install's ingest address (overrides discovery) |
139
+ | `REDBERRY_CLOUD` | `gcp`, `aws` or `azure`, when it cannot be detected |
140
+ | `REDBERRY_API_URL` | the Redberry API (Azure discovery) |
141
+ | `REDBERRY_AZURE_APP_ID_URI` | Redberry's application ID URI in Entra ID, if not the default |
142
+ | `REDBERRY_GCP_REGION` | the install's region on Google Cloud, when it cannot be detected |
143
+ | `REDBERRY_OTEL_ENDPOINT` | an OTLP/HTTP endpoint to send to instead (for testing) |
144
+ | `REDBERRY_AUTH_RETRY_S` | how long a refused batch is retried while access is being granted (default 300) |
145
+ | `REDBERRY_AGENT_ID` | the agent's name, if not passed to `init()` |
146
+ | `REDBERRY_ALLOW_MISSING_INSTRUMENTATION` | `1` to start even when a library's instrumentation is not installed |
147
+ | `REDBERRY_ALLOW_CONTENT_CAPTURE_OFF` | `1` to record metadata only, deliberately |
148
+ | `REDBERRY_MAX_REQUEST_SNAPSHOT_BYTES` | the largest request recorded verbatim |
149
+
150
+ Settings can also be placed in a `.env` file next to the agent. Settings from earlier versions of the SDK, under a
151
+ different prefix, are still accepted.
152
+
153
+ Records the SDK could not deliver are counted by `redberry_sdk.dropped_spans()`.
154
+
155
+ ## License
156
+
157
+ Apache License 2.0. See [LICENSE](LICENSE) and [NOTICE](NOTICE).
@@ -0,0 +1,86 @@
1
+ # redberry-sdk
2
+
3
+ Records an AI agent's model and tool calls with OpenTelemetry and sends them to the customer's own Redberry
4
+ install. Redberry uses these records to keep a tamper-evident evidence chain for each agent and to price its risk.
5
+
6
+ The SDK sends only to the Redberry install in your own cloud account (or to an endpoint you set). It does not
7
+ send anything to Redberry directly.
8
+
9
+ ## Install
10
+
11
+ ```bash
12
+ pip install redberry-sdk # core
13
+ pip install "redberry-sdk[providers]" # plus instrumentation for model providers (OpenAI, Anthropic, ...)
14
+ pip install "redberry-sdk[all]" # providers, agent frameworks and vector databases
15
+ ```
16
+
17
+ Python 3.11 or later.
18
+
19
+ | Extra | Installs instrumentation for |
20
+ |---|---|
21
+ | `providers` | OpenAI, Anthropic, Amazon Bedrock, Cohere, Mistral, Ollama, Vertex AI, Google GenAI, Groq, Together, Replicate |
22
+ | `frameworks` | LangChain, LlamaIndex, CrewAI, Haystack, OpenAI Agents SDK |
23
+ | `vectordb` | Chroma, Pinecone, Qdrant, Weaviate |
24
+ | `openai-agents` | the OpenAI Agents SDK itself, for its `valp.*` integration |
25
+ | `hasher` | the optional per-run signing path |
26
+
27
+ ## Quick start
28
+
29
+ ```python
30
+ import redberry_sdk
31
+
32
+ redberry_sdk.init(agent="refund-agent") # your agent's name, as you will approve it in the Redberry portal
33
+ ```
34
+
35
+ Call `init()` once, before the agent makes its first model call. Model calls made through supported libraries are
36
+ then recorded automatically.
37
+
38
+ **Serverless functions** (AWS Lambda, Azure Functions, Cloud Run functions) can be frozen as soon as a request
39
+ returns. Flush before returning:
40
+
41
+ ```python
42
+ @redberry_sdk.flush_after
43
+ def handler(event, context):
44
+ ...
45
+ ```
46
+
47
+ or call `redberry_sdk.flush()` yourself.
48
+
49
+ **Temperature.** Redberry prices an agent from its sampled behaviour, so the agent's model calls must run at
50
+ temperature 1.0.
51
+
52
+ ## Where records go
53
+
54
+ On these platforms the SDK finds your install automatically and authenticates with the platform's own identity;
55
+ no keys are needed:
56
+
57
+ | Platform | How the install is found | Authentication |
58
+ |---|---|---|
59
+ | Google Cloud (Cloud Run services, jobs, functions) | the install in the same project | the service account's ID token |
60
+ | AWS (Lambda, ECS) | `s3://redberry-<account>-<region>/ingest.json` | AWS Signature Version 4 with the role's credentials |
61
+ | Azure (Functions, Container Apps) | the Redberry API, by the managed identity | the managed identity's Entra ID token |
62
+
63
+ Elsewhere, set the ingest address explicitly.
64
+
65
+ | Environment variable | Meaning |
66
+ |---|---|
67
+ | `REDBERRY_INGEST_URL` | the install's ingest address (overrides discovery) |
68
+ | `REDBERRY_CLOUD` | `gcp`, `aws` or `azure`, when it cannot be detected |
69
+ | `REDBERRY_API_URL` | the Redberry API (Azure discovery) |
70
+ | `REDBERRY_AZURE_APP_ID_URI` | Redberry's application ID URI in Entra ID, if not the default |
71
+ | `REDBERRY_GCP_REGION` | the install's region on Google Cloud, when it cannot be detected |
72
+ | `REDBERRY_OTEL_ENDPOINT` | an OTLP/HTTP endpoint to send to instead (for testing) |
73
+ | `REDBERRY_AUTH_RETRY_S` | how long a refused batch is retried while access is being granted (default 300) |
74
+ | `REDBERRY_AGENT_ID` | the agent's name, if not passed to `init()` |
75
+ | `REDBERRY_ALLOW_MISSING_INSTRUMENTATION` | `1` to start even when a library's instrumentation is not installed |
76
+ | `REDBERRY_ALLOW_CONTENT_CAPTURE_OFF` | `1` to record metadata only, deliberately |
77
+ | `REDBERRY_MAX_REQUEST_SNAPSHOT_BYTES` | the largest request recorded verbatim |
78
+
79
+ Settings can also be placed in a `.env` file next to the agent. Settings from earlier versions of the SDK, under a
80
+ different prefix, are still accepted.
81
+
82
+ Records the SDK could not deliver are counted by `redberry_sdk.dropped_spans()`.
83
+
84
+ ## License
85
+
86
+ Apache License 2.0. See [LICENSE](LICENSE) and [NOTICE](NOTICE).
@@ -0,0 +1,96 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "redberry-sdk"
7
+ dynamic = ["version"]
8
+ description = "Records an AI agent's model and tool calls with OpenTelemetry and sends them to the customer's Redberry install."
9
+ readme = "README.md"
10
+ license = "Apache-2.0"
11
+ license-files = ["LICENSE", "NOTICE"]
12
+ authors = [{ name = "Redberry Labs" }]
13
+ requires-python = ">=3.11"
14
+ keywords = ["opentelemetry", "ai agents", "llm", "observability", "redberry"]
15
+ classifiers = [
16
+ "Development Status :: 4 - Beta",
17
+ "Intended Audience :: Developers",
18
+ "Programming Language :: Python :: 3",
19
+ "Programming Language :: Python :: 3.11",
20
+ "Programming Language :: Python :: 3.12",
21
+ "Programming Language :: Python :: 3.13",
22
+ "Topic :: System :: Monitoring",
23
+ ]
24
+ dependencies = [
25
+ "opentelemetry-api>=1.27",
26
+ "opentelemetry-sdk>=1.27",
27
+ "opentelemetry-exporter-otlp-proto-grpc>=1.27",
28
+ "opentelemetry-exporter-otlp-proto-http>=1.27",
29
+ "requests>=2.31",
30
+ "wrapt>=1.16",
31
+ "pydantic>=2.7",
32
+ "pyyaml>=6.0",
33
+ "python-dotenv>=1.0",
34
+ ]
35
+
36
+ [project.optional-dependencies]
37
+ providers = [
38
+ "opentelemetry-instrumentation-openai-v2>=2.0b0,<2.4",
39
+ "httpx>=0.27",
40
+ "wrapt>=1.17,<2",
41
+ "openinference-instrumentation-anthropic>=0.1",
42
+ "opentelemetry-instrumentation-bedrock>=0.60",
43
+ "opentelemetry-instrumentation-cohere>=0.60",
44
+ "opentelemetry-instrumentation-mistralai>=0.60",
45
+ "opentelemetry-instrumentation-ollama>=0.60",
46
+ "opentelemetry-instrumentation-vertexai>=0.60",
47
+ "opentelemetry-instrumentation-google-generativeai>=0.60",
48
+ "openinference-instrumentation-google-genai>=1.4",
49
+ "opentelemetry-instrumentation-groq>=0.60",
50
+ "opentelemetry-instrumentation-together>=0.60",
51
+ "opentelemetry-instrumentation-replicate>=0.60",
52
+ ]
53
+ frameworks = [
54
+ "opentelemetry-instrumentation-langchain>=0.1",
55
+ "opentelemetry-instrumentation-llamaindex>=0.60",
56
+ "opentelemetry-instrumentation-crewai>=0.60",
57
+ "opentelemetry-instrumentation-haystack>=0.60",
58
+ # 2.7 no longer exports the span of a tool call paused for approval
59
+ "openinference-instrumentation-openai-agents>=2.0,<2.6",
60
+ ]
61
+ vectordb = [
62
+ "opentelemetry-instrumentation-chromadb>=0.60",
63
+ "opentelemetry-instrumentation-pinecone>=0.60",
64
+ "opentelemetry-instrumentation-qdrant>=0.60",
65
+ "opentelemetry-instrumentation-weaviate>=0.60",
66
+ ]
67
+ openai-agents = ["openai-agents>=0.22"]
68
+ hasher = ["cryptography>=42"]
69
+ all = ["redberry-sdk[providers,frameworks,vectordb]"]
70
+ dev = ["cryptography>=42", "pytest>=8.0", "pytest-asyncio>=0.24", "httpx>=0.27", "respx>=0.21", "ruff>=0.6"]
71
+
72
+ [project.urls]
73
+ Homepage = "https://github.com/RedberryLabs/redberry-python"
74
+ Source = "https://github.com/RedberryLabs/redberry-python"
75
+ Changelog = "https://github.com/RedberryLabs/redberry-python/blob/main/CHANGELOG.md"
76
+
77
+ [tool.setuptools.dynamic]
78
+ version = { attr = "redberry_sdk._version.__version__" }
79
+
80
+ [tool.setuptools.packages.find]
81
+ where = ["src"]
82
+ include = ["redberry_sdk*"]
83
+
84
+ [tool.pytest.ini_options]
85
+ testpaths = ["tests"]
86
+ asyncio_mode = "auto"
87
+
88
+ [tool.ruff]
89
+ line-length = 120
90
+ target-version = "py311"
91
+
92
+ [tool.ruff.lint]
93
+ select = ["E4", "E7", "E9", "F"]
94
+
95
+ [tool.ruff.lint.per-file-ignores]
96
+ "tests/**" = ["F811"] # pytest fixtures imported and then used as arguments
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,20 @@
1
+ """Redberry SDK: records an AI agent's model and tool calls and sends them to the customer's Redberry install.
2
+
3
+ Usage::
4
+
5
+ import redberry_sdk
6
+ redberry_sdk.init(agent="my-agent")
7
+
8
+ After init(), model calls made through supported libraries (OpenAI, Anthropic, LangChain and others) are
9
+ recorded with OpenTelemetry and sent to the ingest service of the Redberry install in the customer's own cloud
10
+ (Google Cloud, AWS or Azure), or to an explicit endpoint.
11
+ """
12
+
13
+ from ._sdk import ContentCaptureDisabledError, MissingInstrumentationError, flush, flush_after, init, get_tracer, shutdown
14
+ from ._call_role import internal_call
15
+ from ._emit import dropped_spans
16
+ from ._config import SDKConfig, EvaluationTopology
17
+ from ._coverage import CoverageReport
18
+ from ._version import __version__
19
+
20
+ __all__ = ["__version__", "init", "dropped_spans", "flush", "flush_after", "get_tracer", "shutdown", "internal_call", "MissingInstrumentationError", "ContentCaptureDisabledError", "SDKConfig", "EvaluationTopology", "CoverageReport"]
@@ -0,0 +1,78 @@
1
+ """``internal_call()``: mark the model calls an agent makes for itself.
2
+
3
+ A control's verifier, a judge, a planner or a summariser is a model call whose output stays inside
4
+ the agent. Recorded like any other call, its text became a message to the user: RAP's G3 verifier
5
+ put 11 ``ACCEPT`` / ``REJECT`` "replies" into one airline trace. Wrap such a call::
6
+
7
+ with redberry_sdk.internal_call("verifier"):
8
+ resp = client.chat.completions.create(...)
9
+
10
+ and every span started inside the block carries ``redberry.call_role = "internal"`` and
11
+ ``redberry.call_name = "verifier"``. The normaliser then records the call under the trace's
12
+ ``metadata.internal_calls`` and not as an event (``redberry_normaliser._call_role``).
13
+
14
+ Mark only calls whose output the agent consumes itself. A call whose tool calls the agent
15
+ dispatches is the agent acting, and must not be marked.
16
+
17
+ The marker is a ``contextvars`` value, so it follows the call into ``await`` and stays out of
18
+ other threads and tasks. Without ``redberry_sdk.init()`` it does nothing, and costs nothing.
19
+
20
+ ``redberry.*``, not ``valp.*``: ``valp.*`` is VALP's frozen evidence vocabulary
21
+ (``redberry_sdk.valp``), and a new key there is a VALP specification change.
22
+ """
23
+ from __future__ import annotations
24
+
25
+ import contextvars
26
+ from contextlib import contextmanager
27
+ from typing import Iterator
28
+
29
+ from opentelemetry.context import Context
30
+ from opentelemetry.sdk.trace import ReadableSpan, Span, SpanProcessor
31
+
32
+ #: Read by ``redberry_normaliser._call_role``; kept in step with it.
33
+ CALL_ROLE_ATTR = "redberry.call_role"
34
+ CALL_NAME_ATTR = "redberry.call_name"
35
+ INTERNAL = "internal"
36
+
37
+ _role: contextvars.ContextVar[tuple[str, str | None] | None] = contextvars.ContextVar(
38
+ "redberry_call_role", default=None)
39
+
40
+
41
+ @contextmanager
42
+ def internal_call(name: str | None = None) -> Iterator[None]:
43
+ """Mark every span started inside the block as an internal call named ``name``."""
44
+ if name is not None and not isinstance(name, str):
45
+ raise TypeError(f"internal_call name must be a string, got {type(name).__name__}")
46
+ token = _role.set((INTERNAL, name))
47
+ try:
48
+ yield
49
+ finally:
50
+ _role.reset(token)
51
+
52
+
53
+ def current_call_role() -> tuple[str, str | None] | None:
54
+ """``(role, name)`` inside ``internal_call()``, else None."""
55
+ return _role.get()
56
+
57
+
58
+ class CallRoleSpanProcessor(SpanProcessor):
59
+ """Stamps ``redberry.call_role`` / ``redberry.call_name`` at span start inside ``internal_call()``."""
60
+
61
+ def on_start(self, span: Span, parent_context: Context | None = None) -> None:
62
+ role = _role.get()
63
+ if role is None:
64
+ return
65
+ attrs = span.attributes or {}
66
+ if CALL_ROLE_ATTR not in attrs:
67
+ span.set_attribute(CALL_ROLE_ATTR, role[0])
68
+ if role[1] and CALL_NAME_ATTR not in attrs:
69
+ span.set_attribute(CALL_NAME_ATTR, role[1])
70
+
71
+ def on_end(self, span: ReadableSpan) -> None:
72
+ pass
73
+
74
+ def shutdown(self) -> None:
75
+ pass
76
+
77
+ def force_flush(self, timeout_millis: int = 30000) -> bool:
78
+ return True