responsible-ai-platform 1.0.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 (22) hide show
  1. responsible_ai_platform-1.0.0/LICENSE +201 -0
  2. responsible_ai_platform-1.0.0/NOTICE +7 -0
  3. responsible_ai_platform-1.0.0/PKG-INFO +377 -0
  4. responsible_ai_platform-1.0.0/README.md +339 -0
  5. responsible_ai_platform-1.0.0/pyproject.toml +61 -0
  6. responsible_ai_platform-1.0.0/responsible_ai_platform/__init__.py +15 -0
  7. responsible_ai_platform-1.0.0/responsible_ai_platform/_internal/__init__.py +4 -0
  8. responsible_ai_platform-1.0.0/responsible_ai_platform/_internal/auth.py +46 -0
  9. responsible_ai_platform-1.0.0/responsible_ai_platform/_internal/config.py +69 -0
  10. responsible_ai_platform-1.0.0/responsible_ai_platform/_internal/uploader.py +165 -0
  11. responsible_ai_platform-1.0.0/responsible_ai_platform/agentic/__init__.py +45 -0
  12. responsible_ai_platform-1.0.0/responsible_ai_platform/agentic/context.py +20 -0
  13. responsible_ai_platform-1.0.0/responsible_ai_platform/agentic/decorators.py +196 -0
  14. responsible_ai_platform-1.0.0/responsible_ai_platform/agentic/integrations/__init__.py +18 -0
  15. responsible_ai_platform-1.0.0/responsible_ai_platform/agentic/integrations/langgraph.py +229 -0
  16. responsible_ai_platform-1.0.0/responsible_ai_platform/agentic/trace.py +532 -0
  17. responsible_ai_platform-1.0.0/responsible_ai_platform.egg-info/PKG-INFO +377 -0
  18. responsible_ai_platform-1.0.0/responsible_ai_platform.egg-info/SOURCES.txt +20 -0
  19. responsible_ai_platform-1.0.0/responsible_ai_platform.egg-info/dependency_links.txt +1 -0
  20. responsible_ai_platform-1.0.0/responsible_ai_platform.egg-info/requires.txt +9 -0
  21. responsible_ai_platform-1.0.0/responsible_ai_platform.egg-info/top_level.txt +1 -0
  22. responsible_ai_platform-1.0.0/setup.cfg +4 -0
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for describing the origin of the Work and
141
+ reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may accept and charge a
167
+ fee for the acceptance of support, warranty, indemnity, or other
168
+ liability obligations and/or rights consistent with this License.
169
+ However, in accepting such obligations, You may act only on Your
170
+ own behalf and on Your sole responsibility, not on behalf of any
171
+ other Contributor, and only if You agree to indemnify, defend,
172
+ and hold each Contributor harmless for any liability incurred by,
173
+ or claims asserted against, such Contributor by reason of your
174
+ accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Cirrus Labs — RAIA
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,7 @@
1
+ responsible-ai-platform
2
+ Copyright 2026 Cirrus Labs — RAIA
3
+
4
+ This product includes software developed by Cirrus Labs as part of the
5
+ Responsible AI Platform (RAIA).
6
+
7
+ Contact: raiaadmin@cirruslabs.io
@@ -0,0 +1,377 @@
1
+ Metadata-Version: 2.4
2
+ Name: responsible-ai-platform
3
+ Version: 1.0.0
4
+ Summary: Responsible AI Platform — SDK for tracing, evaluation, and governance of AI assets
5
+ Author-email: RAIA <raiaadmin@cirruslabs.io>
6
+ Maintainer-email: RAIA <raiaadmin@cirruslabs.io>
7
+ License: Apache-2.0
8
+ Project-URL: Homepage, https://github.com/CL-AI-COE/trace-sdk
9
+ Project-URL: Repository, https://github.com/CL-AI-COE/trace-sdk
10
+ Project-URL: Issues, https://github.com/CL-AI-COE/trace-sdk/issues
11
+ Project-URL: Changelog, https://github.com/CL-AI-COE/trace-sdk/releases
12
+ Keywords: responsible-ai,ai-evaluation,ai-governance,agent-tracing,llm-observability,agentic-ai
13
+ Classifier: Development Status :: 5 - Production/Stable
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Intended Audience :: Information Technology
16
+ Classifier: License :: OSI Approved :: Apache Software License
17
+ Classifier: Operating System :: OS Independent
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3.9
20
+ Classifier: Programming Language :: Python :: 3.10
21
+ Classifier: Programming Language :: Python :: 3.11
22
+ Classifier: Programming Language :: Python :: 3.12
23
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
24
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
25
+ Requires-Python: >=3.9
26
+ Description-Content-Type: text/markdown
27
+ License-File: LICENSE
28
+ License-File: NOTICE
29
+ Requires-Dist: requests<3.0.0,>=2.28.0
30
+ Requires-Dist: python-dotenv<2.0.0,>=1.0.0
31
+ Provides-Extra: dev
32
+ Requires-Dist: pytest>=7.0; extra == "dev"
33
+ Requires-Dist: black; extra == "dev"
34
+ Requires-Dist: isort; extra == "dev"
35
+ Requires-Dist: build>=1.0; extra == "dev"
36
+ Requires-Dist: twine>=4.0; extra == "dev"
37
+ Dynamic: license-file
38
+
39
+ # RAIA Trace SDK
40
+
41
+ Python SDK for logging agent trace data to the RAIA platform. Works with **any** agent framework — LangGraph, LangChain, CrewAI, or custom Python agents.
42
+
43
+ Trace logs are uploaded as JSON to S3 via the RAIA API and used by the evaluation service to compute metrics like latency, token usage, tool governance, safety, quality, and trust scores.
44
+
45
+ ## Installation
46
+
47
+ ```bash
48
+ pip install /path/to/raia-trace-sdk
49
+ ```
50
+
51
+ ## Configuration
52
+
53
+ ### API Key (Recommended)
54
+
55
+ Generate an API key from the RAIA UI (Assess → your asset → API Key button). Then add to your `.env`:
56
+
57
+ ```env
58
+ RAIA_API_KEY=eyJhbGciOiJIUzI1NiJ9...
59
+ RAIA_API_BASE_URL=https://raia-dev.cirruslabs.io
60
+ ```
61
+
62
+ That's it — just 2 variables. The API key contains your project name, tenant, and all routing information.
63
+
64
+ | Variable | Required | Description |
65
+ |---|---|---|
66
+ | `RAIA_API_KEY` | Yes | API key from RAIA UI (valid for 90 days) |
67
+ | `RAIA_API_BASE_URL` | Yes | RAIA API URL |
68
+
69
+ ### Optional Variables
70
+
71
+ ```env
72
+ RAIA_AGENT_VERSION=1.0.0
73
+ RAIA_MODEL_VERSION=claude-sonnet-4-6
74
+ RAIA_ENVIRONMENT=dev
75
+ RAIA_MAX_STEPS_ALLOWED=15
76
+ RAIA_DEBUG=true
77
+ ```
78
+
79
+ ## Integration Options
80
+
81
+ ### Option 1: LangGraph / LangChain (Recommended)
82
+
83
+ Use the built-in integration that auto-extracts tool calls, token usage, input/output, and thinking steps from LangGraph messages.
84
+
85
+ ```python
86
+ from datetime import datetime, timezone
87
+ from langchain_core.messages import HumanMessage, SystemMessage
88
+ from langgraph.prebuilt import create_react_agent
89
+
90
+ from responsible_ai_platform.agentic import AgentTrace
91
+ from responsible_ai_platform.agentic.integrations import log_langgraph_steps
92
+
93
+ SYSTEM_PROMPT = "You are a helpful assistant..."
94
+ TOOL_REGISTRY = ["search_products", "get_order_details"]
95
+
96
+ # Configure once at startup (optional — sets defaults for all traces)
97
+ AgentTrace.configure(
98
+ system_prompt=SYSTEM_PROMPT,
99
+ tool_registry=TOOL_REGISTRY,
100
+ )
101
+
102
+ # Create your LangGraph agent
103
+ agent = create_react_agent(llm, tools, prompt=SystemMessage(content=SYSTEM_PROMPT))
104
+
105
+ # --- Per-call usage (one trace per request) ---
106
+ with AgentTrace(task_description="Customer support query") as trace:
107
+ start_time = datetime.now(timezone.utc)
108
+ result = agent.invoke({"messages": [HumanMessage(content="Show me laptops")]})
109
+ end_time = datetime.now(timezone.utc)
110
+
111
+ log_langgraph_steps(
112
+ trace,
113
+ result["messages"],
114
+ user_input="Show me laptops",
115
+ start_time=start_time,
116
+ end_time=end_time,
117
+ )
118
+ trace.set_outcome("success")
119
+ # Trace auto-uploads to S3 on exit
120
+ ```
121
+
122
+ ### Option 2: Session-Based Tracing (Multi-Turn Chat)
123
+
124
+ For chat applications where one conversation = one trace file with multiple entries.
125
+
126
+ ```python
127
+ from responsible_ai_platform.agentic import AgentTrace
128
+ from responsible_ai_platform.agentic.integrations import log_langgraph_steps
129
+
130
+ # Create a session-level trace (lives for the entire conversation)
131
+ trace = AgentTrace(
132
+ task_description="Customer support session",
133
+ session_id="unique-session-id",
134
+ )
135
+ trace._async_upload = False # Synchronous uploads (reliable)
136
+ trace._auto_upload = True # Auto-upload after each message
137
+ trace.start()
138
+
139
+ # Each user message adds an entry to the same trace
140
+ def handle_message(user_input: str):
141
+ start_time = datetime.now(timezone.utc)
142
+ result = agent.invoke({"messages": [HumanMessage(content=user_input)]})
143
+ end_time = datetime.now(timezone.utc)
144
+
145
+ log_langgraph_steps(
146
+ trace,
147
+ result["messages"],
148
+ user_input=user_input,
149
+ start_time=start_time,
150
+ end_time=end_time,
151
+ )
152
+ # With _auto_upload=True, the trace JSON is uploaded to S3 after each call
153
+
154
+ # When the session ends
155
+ trace.set_outcome("success")
156
+ trace.finish() # Final upload
157
+ ```
158
+
159
+ ### Option 3: Decorator-Based (Custom Agents)
160
+
161
+ For custom Python agents without a framework. Use `@trace` on the agent entry point and `@tool` on tool functions.
162
+
163
+ ```python
164
+ from responsible_ai_platform.agentic import trace, tool
165
+
166
+ @tool
167
+ def search_products(query: str) -> str:
168
+ """Search the product catalog."""
169
+ # your implementation
170
+ return results
171
+
172
+ @tool
173
+ def get_order(order_id: str) -> dict:
174
+ """Look up an order."""
175
+ return {"order_id": order_id, "status": "delivered"}
176
+
177
+ @trace(task_description="Handle customer query")
178
+ def my_agent(query: str) -> str:
179
+ results = search_products(query)
180
+ return f"Found: {results}"
181
+
182
+ # Just call the function — tracing happens automatically
183
+ my_agent("Show me laptops under $500")
184
+ # Trace auto-created, all @tool calls logged, uploaded to S3
185
+ ```
186
+
187
+ The `@tool` decorator auto-captures: tool name, arguments, result, latency, and errors. It requires an active `@trace` context — if no trace is active, the function runs normally.
188
+
189
+ ### Option 4: Manual Logging (Any Framework)
190
+
191
+ For full control over what gets logged. Works with any agent framework.
192
+
193
+ ```python
194
+ from responsible_ai_platform.agentic import AgentTrace
195
+
196
+ with AgentTrace(task_description="My agent task") as trace:
197
+ trace.log_interaction(
198
+ input_text="What laptops do you have?",
199
+ output_text="Here are our top laptops...",
200
+ model="claude-sonnet-4-6",
201
+ prompt_tokens=150,
202
+ completion_tokens=200,
203
+ total_tokens=350,
204
+ success=True,
205
+ tool_calls=[
206
+ {"name": "search_products", "arguments": {"query": "laptops"}, "is_authorized": True}
207
+ ],
208
+ tool_results=[
209
+ {"name": "search_products", "result": "Found 5 laptops..."}
210
+ ],
211
+ )
212
+ trace.set_outcome("success")
213
+ ```
214
+
215
+ ## API Reference
216
+
217
+ ### `AgentTrace`
218
+
219
+ The core tracing class.
220
+
221
+ #### Class Method
222
+
223
+ ```python
224
+ AgentTrace.configure(
225
+ tenant_id=None, # Override tenant from .env
226
+ app_id=None, # Override app_id from .env
227
+ agent_version=None, # Override agent_version from .env
228
+ model_version=None, # Override model_version from .env
229
+ environment=None, # Override environment from .env
230
+ system_prompt=None, # Default system prompt for all traces
231
+ tool_registry=None, # List of authorized tool names
232
+ )
233
+ ```
234
+
235
+ #### Constructor
236
+
237
+ ```python
238
+ trace = AgentTrace(
239
+ app_id=None, # Agent application ID
240
+ task_description="", # What this trace is about
241
+ session_id=None, # Session ID (auto-generated if omitted)
242
+ max_steps_allowed=None, # Max tool steps
243
+ metadata=None, # Extra metadata dict
244
+ system_prompt=None, # System prompt text
245
+ tool_registry=None, # List of authorized tool names
246
+ expected_outcome=None, # Ground truth for evaluation
247
+ )
248
+ ```
249
+
250
+ #### Methods
251
+
252
+ | Method | Description |
253
+ |---|---|
254
+ | `start()` | Start the trace timer. Called automatically when using `with`. |
255
+ | `finish()` | Finalize and upload the trace. Called automatically when using `with`. |
256
+ | `log_interaction(...)` | Log a single user-agent interaction (message pair). |
257
+ | `log_step(...)` | Log a single tool invocation (used by `@tool` decorator). |
258
+ | `set_outcome(outcome, escalation_reason=None)` | Set outcome: `"success"`, `"failure"`, `"partial"`, `"escalated"`. |
259
+ | `log_boundary_violation(action, rule_violated)` | Record a policy constraint violation. |
260
+ | `to_dict()` | Serialize trace as list of entry dicts. |
261
+
262
+ #### `log_interaction()` Parameters
263
+
264
+ ```python
265
+ trace.log_interaction(
266
+ input_text="user query", # User message
267
+ output_text="agent response", # Agent response
268
+ start_time=None, # datetime (defaults to now)
269
+ end_time=None, # datetime (defaults to now)
270
+ model=None, # LLM model used
271
+ prompt_tokens=0, # Input token count
272
+ completion_tokens=0, # Output token count
273
+ total_tokens=0, # Total tokens
274
+ success=True, # Whether interaction succeeded
275
+ error_type=None, # Exception class name
276
+ error_message=None, # Error details
277
+ tool_calls=None, # List of {name, arguments, is_authorized}
278
+ tool_results=None, # List of {name, result}
279
+ agent_thinking=None, # List of reasoning steps
280
+ num_steps=None, # Number of agent steps
281
+ task_description=None, # Per-interaction task description
282
+ system_prompt=None, # System prompt override
283
+ expected_outcome=None, # Ground truth override
284
+ boundary_violations=None, # List of violations
285
+ escalation_events=None, # List of escalation events
286
+ escalation_reason=None, # Escalation reason text
287
+ )
288
+ ```
289
+
290
+ ### `log_langgraph_steps()`
291
+
292
+ One-line integration for LangGraph/LangChain agents.
293
+
294
+ ```python
295
+ from responsible_ai_platform.agentic.integrations import log_langgraph_steps
296
+
297
+ log_langgraph_steps(
298
+ trace, # Active AgentTrace instance
299
+ messages, # List of LangChain message objects from agent.invoke()
300
+ user_input=None, # Original user query (auto-detected if omitted)
301
+ start_time=None, # When the invocation started
302
+ end_time=None, # When the invocation ended
303
+ )
304
+ ```
305
+
306
+ Auto-extracts from messages:
307
+ - **Input/Output**: First `HumanMessage` and last `AIMessage`
308
+ - **Tool calls**: From `AIMessage.tool_calls` with `is_authorized=True`
309
+ - **Tool results**: From `ToolMessage` objects, paired by `tool_call_id`
310
+ - **Token usage**: From `AIMessage.usage_metadata` (`input_tokens`, `output_tokens`)
311
+ - **System prompt**: From `SystemMessage` if present
312
+ - **Model**: From `AIMessage.response_metadata`
313
+ - **Thinking steps**: Reconstructed from AI message + tool call sequence
314
+
315
+ ## Trace Output Format
316
+
317
+ Each trace is a JSON array of entries (one per user interaction):
318
+
319
+ ```json
320
+ [
321
+ {
322
+ "trace_id": "uuid",
323
+ "session_id": "uuid",
324
+ "start_time": "2024-01-01T00:00:00+00:00",
325
+ "end_time": "2024-01-01T00:00:01+00:00",
326
+ "latency": 1000.0,
327
+ "input": "Show me laptops",
328
+ "output": "Here are our top laptops...",
329
+ "system_prompt": "You are a helpful assistant...",
330
+ "task_description": "Customer support query",
331
+ "expected_outcome": null,
332
+ "model": "claude-sonnet-4-6",
333
+ "prompt_tokens": 150,
334
+ "completion_tokens": 200,
335
+ "total_tokens": 350,
336
+ "success": true,
337
+ "status": "success",
338
+ "error_type": null,
339
+ "error_message": null,
340
+ "tool_calls": [
341
+ {"name": "search_products", "arguments": {"query": "laptops"}, "is_authorized": true}
342
+ ],
343
+ "tool_results": [
344
+ {"name": "search_products", "result": "Found 5 laptops..."}
345
+ ],
346
+ "tool_registry": ["search_products", "get_order_details"],
347
+ "agent_thinking": [
348
+ {"step": 1, "thought": "User wants laptop recommendations", "action": "search_products"}
349
+ ],
350
+ "num_steps": 1,
351
+ "boundary_violations": [],
352
+ "escalation_events": [],
353
+ "escalation_reason": null,
354
+ "app_id": "my-agent-app",
355
+ "tenant_id": "MyTenant",
356
+ "agent_version": "1.0.0",
357
+ "environment": "dev"
358
+ }
359
+ ]
360
+ ```
361
+
362
+ ## S3 Upload Path
363
+
364
+ Traces are uploaded to:
365
+
366
+ ```
367
+ {tenant_name}/{analysis_type}/{project_name}/files/{session_id}.json
368
+ ```
369
+
370
+ - With `_auto_upload=True`, the file is overwritten after each message (growing array)
371
+ - On `finish()`, a final upload is done with the complete trace
372
+
373
+ ## Error Handling
374
+
375
+ - If the RAIA API is unreachable, traces are saved to `~/.raia/buffer/` as local JSON files
376
+ - Authentication errors raise immediately so you can fix credentials
377
+ - Individual interaction errors are captured in the trace (`success=false`, `error_type`, `error_message`)