agent-trajectory 0.2.3__py3-none-any.whl

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.
@@ -0,0 +1,211 @@
1
+ Metadata-Version: 2.4
2
+ Name: agent-trajectory
3
+ Version: 0.2.3
4
+ Summary: Normalize native agent transcripts into a shared trajectory format.
5
+ Author: Letta
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Repository, https://github.com/letta-ai/trajectory
8
+ Keywords: agents,transcripts,normalization,training
9
+ Classifier: Development Status :: 3 - Alpha
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.10
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Typing :: Typed
15
+ Requires-Python: >=3.10
16
+ Description-Content-Type: text/markdown
17
+ License-File: LICENSE
18
+ Provides-Extra: deepagents
19
+ Requires-Dist: langgraph<2,>=1.1; extra == "deepagents"
20
+ Requires-Dist: langgraph-checkpoint-sqlite<4,>=3; extra == "deepagents"
21
+ Dynamic: license-file
22
+
23
+ # trajectory
24
+
25
+ Normalize agent transcripts from different runtimes into one validated,
26
+ model-ready record format.
27
+
28
+ Agent tools represent the same concepts—messages, reasoning, tool calls, and
29
+ tool results—in incompatible native formats. `trajectory` provides one
30
+ TypeScript API that turns those formats into deterministic,
31
+ structured records for training, evaluation, analysis, and inference.
32
+
33
+ The caller supplies a transcript string and its source. The one exception is
34
+ Deep Agents, whose sessions `normalizeCheckpoint` reads from its local
35
+ LangGraph SQLite store by thread ID; see
36
+ [`src/adapters/deepagents/`](src/adapters/deepagents/).
37
+
38
+ ## Installation
39
+
40
+ The TypeScript package is published as
41
+ [`@letta-ai/trajectory`](https://www.npmjs.com/package/@letta-ai/trajectory):
42
+
43
+ ```sh
44
+ npm install @letta-ai/trajectory
45
+ ```
46
+
47
+ The Python wrapper is published as
48
+ [`agent-trajectory`](https://pypi.org/project/agent-trajectory/) and imports as
49
+ `trajectory`:
50
+
51
+ ```sh
52
+ pip install agent-trajectory
53
+ ```
54
+
55
+ ## Quick start
56
+
57
+ ```ts
58
+ import { normalizeTranscript } from "@letta-ai/trajectory";
59
+
60
+ const { records, diagnostics } = normalizeTranscript({
61
+ source: "codex",
62
+ transcript: rawJsonl,
63
+ });
64
+ ```
65
+
66
+ `records` contains the normalized trajectory. `diagnostics` is always present
67
+ and is empty when the transcript required no recoverable cleanup.
68
+
69
+ ```json
70
+ {
71
+ "records": [
72
+ { "role": "meta", "source": "codex" },
73
+ {
74
+ "role": "user",
75
+ "content": "Check the current directory.",
76
+ "timestamp": "2026-07-10T12:00:00.000Z"
77
+ },
78
+ {
79
+ "role": "assistant",
80
+ "content": null,
81
+ "tool_calls": [
82
+ {
83
+ "id": "call_1",
84
+ "name": "exec_command",
85
+ "args": "{\"cmd\":\"pwd\"}"
86
+ }
87
+ ],
88
+ "timestamp": "2026-07-10T12:00:01.000Z"
89
+ },
90
+ {
91
+ "role": "tool",
92
+ "tool_call_id": "call_1",
93
+ "content": "/workspace",
94
+ "timestamp": "2026-07-10T12:00:02.000Z"
95
+ }
96
+ ],
97
+ "diagnostics": []
98
+ }
99
+ ```
100
+
101
+ ## Supported sources
102
+
103
+ | `source` | Accepted input format | Normalized `meta.source` |
104
+ | --- | --- | --- |
105
+ | [`claude-code`](src/adapters/claude-code/) | Native Claude Code JSONL | `claude-code` |
106
+ | [`codex`](src/adapters/codex/) | Native Codex rollout JSONL | `codex` |
107
+ | [`copilot-cli`](src/adapters/copilot-cli/) | Native GitHub Copilot CLI event JSONL | `copilot-cli` |
108
+ | [`cursor`](src/adapters/cursor/) | Cursor role/message content-block JSONL capture | `cursor` |
109
+ | [`droid`](src/adapters/droid/) | Native Droid session JSONL | `droid` |
110
+ | [`gemini-cli`](src/adapters/gemini-cli/) | Native Gemini CLI whole-session JSON | `gemini-cli` |
111
+ | [`hermes`](src/adapters/hermes/) | Session-store message-row array or a `{ "session": {...}, "messages": [...] }` envelope | `hermes` |
112
+ | [`letta-code`](src/adapters/letta-code/) | Letta Code client `transcript.jsonl` | `letta-code` |
113
+ | [`omp`](src/adapters/omp/) | Native OMP (Oh My Pi) coding-agent session JSONL (pi-agent session format) | `omp` |
114
+ | [`openclaw`](src/adapters/openclaw/) | Native OpenClaw session JSONL (pi-agent session format) | `openclaw` |
115
+ | [`opencode`](src/adapters/opencode/) | Native OpenCode `{ "info": ..., "messages": [...] }` session JSON | `opencode` |
116
+ | [`openhands`](src/adapters/openhands/) | JSON event array or an events-API `{ "items": [...] }` envelope | `openhands` |
117
+ | [`pi`](src/adapters/pi/) | Native pi-coding-agent session JSONL | `pi` |
118
+ | [`deepagents`](src/adapters/deepagents/) | Deep Agents CLI LangGraph SQLite store plus `threadId` | `deepagents` |
119
+
120
+ Tool result records may include `ok: boolean` when the source exposes an
121
+ authoritative structured outcome, such as Pi/OpenClaw `isError`, Claude Code
122
+ `is_error`, Letta Code `resultOk`, OpenHands/Cursor `is_error`,
123
+ OpenCode/Gemini terminal state, or Copilot CLI `success`. The field is omitted
124
+ when the source does not expose a reliable status; result text is never
125
+ interpreted as success or failure.
126
+
127
+ Each adapter lives in its own folder under [`src/adapters/`](src/adapters/)
128
+ with a README documenting the exact input contract, decoding behavior, and
129
+ what the adapter drops.
130
+
131
+ ## Listing local trajectories
132
+
133
+ `listTrajectories()` enumerates the sessions in a source's standard local
134
+ store, newest first, with cursor pagination. It is a discovery layer beside
135
+ normalization — `normalizeTranscript()` itself never touches the filesystem.
136
+ Copilot CLI, Cursor, Gemini CLI, and OpenCode are export-only input contracts
137
+ and intentionally return `listing_unavailable`; callers locate and read the
138
+ exports themselves.
139
+
140
+ ```ts
141
+ import { listTrajectories } from "@letta-ai/trajectory";
142
+
143
+ let cursor: string | undefined;
144
+ do {
145
+ const page = await listTrajectories({ source: "claude-code", limit: 100, cursor });
146
+ for (const item of page.items) {
147
+ // item.id, item.path, item.updatedAt?, item.title?, item.sizeBytes?
148
+ }
149
+ cursor = page.nextCursor;
150
+ } while (cursor);
151
+ ```
152
+
153
+ ## Normalized records
154
+
155
+ A trajectory is an ordered array containing:
156
+
157
+ - One leading `meta` record identifying the source and available session
158
+ metadata.
159
+ - `user` and assistant prose records.
160
+ - Optional `reasoning` records when the source exposes reasoning.
161
+ - Assistant tool-call records with stable IDs and stringified JSON-object
162
+ arguments.
163
+ - `tool` records linked to earlier calls by `tool_call_id`.
164
+
165
+ Every conversational record has an ISO timestamp. The complete contract is
166
+ available as both runtime validation and
167
+ [`schema/trajectory-v1.schema.json`](schema/trajectory-v1.schema.json).
168
+
169
+ The public function is:
170
+
171
+ ```ts
172
+ normalizeTranscript(input: NormalizeInput): NormalizeResult
173
+ ```
174
+
175
+ ## Adding a source
176
+
177
+ Each native format is implemented as a focused adapter that decodes source
178
+ events into the shared internal message/tool contract. Common validation,
179
+ linking, repair, timestamp handling, and bounds remain in the normalization
180
+ core.
181
+
182
+ Use [`prompts/add-source.md`](prompts/add-source.md) with a coding agent to add
183
+ a source from a local transcript corpus. The prompt covers privacy-safe corpus
184
+ inspection, sanitized fixtures, compatibility checks, and the transcript-only
185
+ API boundary.
186
+
187
+ ## Development
188
+
189
+ Requires Node.js 20+ and [Bun](https://bun.sh/) for development:
190
+
191
+ ```sh
192
+ bun install
193
+ bun run check
194
+ ```
195
+
196
+ `bun run check` runs typechecking, the complete test suite, and the package
197
+ build. It also regenerates the JavaScript runtime embedded in the Python wheel
198
+ and fails if the committed bundle was stale. Run the Python parity suite with:
199
+
200
+ ```sh
201
+ PYTHONPATH=python/src python3 -m unittest discover -s python/tests -v
202
+ ```
203
+
204
+ See [`PARITY.md`](PARITY.md) for compatibility checks performed against real
205
+ transcript corpora and production source adapters.
206
+ See [`SOURCE_VERSION_AUDIT.md`](SOURCE_VERSION_AUDIT.md) for the privacy-safe
207
+ source-version inventory, observed format families, and current decoder gaps.
208
+
209
+ ## License
210
+
211
+ Apache-2.0. See [`LICENSE`](LICENSE).
@@ -0,0 +1,12 @@
1
+ agent_trajectory-0.2.3.dist-info/licenses/LICENSE,sha256=z5Ty5WZhiudvzfGjn81qi1eShO2RiENhnoBP_rpziFw,10759
2
+ trajectory/__init__.py,sha256=85x0TPdM_LSFyaf8LeZKc1Lpi47meUXbP1l0jiD32eM,1917
3
+ trajectory/_client.py,sha256=LFRcU74b4rhdnzGGX5w9Qxd4amwdfGl6l02QoGFvXaY,8203
4
+ trajectory/_errors.py,sha256=FI8el3k5RobL_ubV9NaXZf8suaH2h9jVHjezBYNpMDc,616
5
+ trajectory/_types.py,sha256=zayM7ILMY2UzxD-Ox74WLop9ut4OaBgK3c1SSjyQSus,4695
6
+ trajectory/py.typed,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
7
+ trajectory/_vendor/deepagents_checkpoint.py,sha256=7fMEUw-fQdg0PqS76EXWoe0ja2X2z4hTWxwwyjZLK8A,13018
8
+ trajectory/_vendor/trajectory-cli.mjs,sha256=okIfZRFMC6EZ6T355QiHKrdN45mMaAuHGsiiRseNF6s,121578
9
+ agent_trajectory-0.2.3.dist-info/METADATA,sha256=d9pHqUWIbPEh_G5VRVAIuTtWWJW4JdgqF5AFkMmxlF4,7667
10
+ agent_trajectory-0.2.3.dist-info/WHEEL,sha256=K260EYznzXsJYBQGqmI8VTxEdiZYNvDZwW9cBh9-_MA,91
11
+ agent_trajectory-0.2.3.dist-info/top_level.txt,sha256=JiMfGqr1ugDu6BJRvek3emBUwW_Stqs1gQWvr46e3XM,11
12
+ agent_trajectory-0.2.3.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (83.0.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,190 @@
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 of
111
+ 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 reasonable and customary use in describing the
141
+ origin of the Work and 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 choose to offer, and
167
+ charge a fee for, acceptance of support, warranty, indemnity, or
168
+ other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2025, Letta authors
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
@@ -0,0 +1 @@
1
+ trajectory
trajectory/__init__.py ADDED
@@ -0,0 +1,79 @@
1
+ """Normalize native agent transcripts using the canonical trajectory runtime."""
2
+
3
+ from ._client import (
4
+ list_trajectories,
5
+ normalize_checkpoint,
6
+ normalize_many,
7
+ normalize_transcript,
8
+ )
9
+ from ._errors import NodeUnavailableError, NormalizationError, TrajectoryRuntimeError
10
+ from ._types import (
11
+ AssistantMessageRecord,
12
+ AssistantToolCallRecord,
13
+ AnyTrajectorySource,
14
+ CheckpointTrajectorySource,
15
+ DeepAgentsCheckpointInput,
16
+ DeepAgentsCheckpointLocation,
17
+ Diagnostic,
18
+ DiagnosticCode,
19
+ ListTrajectoriesResult,
20
+ MetaRecord,
21
+ NormalizationBounds,
22
+ NormalizationFilters,
23
+ NormalizationErrorCode,
24
+ NormalizedRecord,
25
+ NormalizeInput,
26
+ NormalizeRequest,
27
+ NormalizeResult,
28
+ SourceContext,
29
+ TrajectoryListing,
30
+ ReasoningRecord,
31
+ ToolCall,
32
+ ToolArgumentBounds,
33
+ ToolResultBounds,
34
+ ToolResultPolicy,
35
+ ToolResultRecord,
36
+ ToolResultTruncationStrategy,
37
+ TrajectorySource,
38
+ UserRecord,
39
+ )
40
+
41
+ __all__ = [
42
+ "AssistantMessageRecord",
43
+ "AssistantToolCallRecord",
44
+ "AnyTrajectorySource",
45
+ "CheckpointTrajectorySource",
46
+ "DeepAgentsCheckpointInput",
47
+ "DeepAgentsCheckpointLocation",
48
+ "Diagnostic",
49
+ "DiagnosticCode",
50
+ "ListTrajectoriesResult",
51
+ "MetaRecord",
52
+ "NodeUnavailableError",
53
+ "NormalizationBounds",
54
+ "NormalizationFilters",
55
+ "NormalizationError",
56
+ "NormalizationErrorCode",
57
+ "NormalizedRecord",
58
+ "NormalizeInput",
59
+ "NormalizeRequest",
60
+ "NormalizeResult",
61
+ "ReasoningRecord",
62
+ "SourceContext",
63
+ "ToolCall",
64
+ "ToolArgumentBounds",
65
+ "ToolResultBounds",
66
+ "ToolResultPolicy",
67
+ "ToolResultRecord",
68
+ "ToolResultTruncationStrategy",
69
+ "TrajectoryListing",
70
+ "TrajectoryRuntimeError",
71
+ "TrajectorySource",
72
+ "UserRecord",
73
+ "list_trajectories",
74
+ "normalize_many",
75
+ "normalize_checkpoint",
76
+ "normalize_transcript",
77
+ ]
78
+
79
+ __version__ = "0.2.3"