courier-encode 0.1.2__tar.gz → 0.1.4__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 (82) hide show
  1. courier_encode-0.1.4/.idea/workspace.xml +105 -0
  2. courier_encode-0.1.4/PKG-INFO +409 -0
  3. courier_encode-0.1.4/README.md +173 -0
  4. courier_encode-0.1.4/docs/async.md +96 -0
  5. courier_encode-0.1.4/docs/concepts.md +118 -0
  6. courier_encode-0.1.4/docs/cookbook.md +383 -0
  7. courier_encode-0.1.4/docs/errors.md +95 -0
  8. courier_encode-0.1.4/docs/executors.md +182 -0
  9. courier_encode-0.1.4/docs/intercept.md +256 -0
  10. courier_encode-0.1.4/docs/messages.md +207 -0
  11. courier_encode-0.1.4/docs/quickstart.md +109 -0
  12. courier_encode-0.1.4/docs/relay.md +134 -0
  13. courier_encode-0.1.4/docs/sessions.md +290 -0
  14. courier_encode-0.1.4/docs/streaming.md +120 -0
  15. courier_encode-0.1.4/docs/structured-output.md +98 -0
  16. courier_encode-0.1.4/docs/terminal.md +171 -0
  17. courier_encode-0.1.4/docs/tools.md +195 -0
  18. courier_encode-0.1.4/docs/whisper.md +95 -0
  19. courier_encode-0.1.4/docs.md +145 -0
  20. courier_encode-0.1.4/examples/intercept_compact.py +61 -0
  21. courier_encode-0.1.4/examples/session_resume.py +66 -0
  22. courier_encode-0.1.4/examples/stateful_tool.py +84 -0
  23. courier_encode-0.1.4/examples/tool_discovery.py +120 -0
  24. {courier_encode-0.1.2 → courier_encode-0.1.4}/pyproject.toml +1 -1
  25. {courier_encode-0.1.2 → courier_encode-0.1.4}/src/encode/__init__.py +25 -5
  26. {courier_encode-0.1.2 → courier_encode-0.1.4}/src/encode/errors.py +4 -4
  27. courier_encode-0.1.4/src/encode/events.py +186 -0
  28. courier_encode-0.1.4/src/encode/executor.py +149 -0
  29. {courier_encode-0.1.2 → courier_encode-0.1.4}/src/encode/messages.py +58 -0
  30. {courier_encode-0.1.2 → courier_encode-0.1.4}/src/encode/relay.py +713 -250
  31. courier_encode-0.1.4/src/encode/session.py +292 -0
  32. courier_encode-0.1.2/src/encode/session.py → courier_encode-0.1.4/src/encode/terminal.py +81 -46
  33. {courier_encode-0.1.2 → courier_encode-0.1.4}/src/encode/tools.py +33 -2
  34. courier_encode-0.1.4/tests/test_executor.py +151 -0
  35. courier_encode-0.1.4/tests/test_intercept_mutation.py +207 -0
  36. courier_encode-0.1.4/tests/test_intercept_tool_discovery.py +243 -0
  37. courier_encode-0.1.4/tests/test_relay_session.py +218 -0
  38. courier_encode-0.1.4/tests/test_session.py +171 -0
  39. courier_encode-0.1.4/tests/test_session_tools.py +148 -0
  40. courier_encode-0.1.2/tests/test_session.py → courier_encode-0.1.4/tests/test_terminal.py +32 -21
  41. courier_encode-0.1.2/.idea/workspace.xml +0 -83
  42. courier_encode-0.1.2/PKG-INFO +0 -1158
  43. courier_encode-0.1.2/README.md +0 -922
  44. courier_encode-0.1.2/docs.md +0 -770
  45. {courier_encode-0.1.2 → courier_encode-0.1.4}/.gitignore +0 -0
  46. {courier_encode-0.1.2 → courier_encode-0.1.4}/.idea/.gitignore +0 -0
  47. {courier_encode-0.1.2 → courier_encode-0.1.4}/.idea/encode.iml +0 -0
  48. {courier_encode-0.1.2 → courier_encode-0.1.4}/.idea/inspectionProfiles/Project_Default.xml +0 -0
  49. {courier_encode-0.1.2 → courier_encode-0.1.4}/.idea/inspectionProfiles/profiles_settings.xml +0 -0
  50. {courier_encode-0.1.2 → courier_encode-0.1.4}/.idea/misc.xml +0 -0
  51. {courier_encode-0.1.2 → courier_encode-0.1.4}/.idea/modules.xml +0 -0
  52. {courier_encode-0.1.2 → courier_encode-0.1.4}/.idea/vcs.xml +0 -0
  53. {courier_encode-0.1.2 → courier_encode-0.1.4}/LICENSE +0 -0
  54. {courier_encode-0.1.2 → courier_encode-0.1.4}/examples/basic_chat.py +0 -0
  55. {courier_encode-0.1.2 → courier_encode-0.1.4}/examples/intercept.py +0 -0
  56. {courier_encode-0.1.2 → courier_encode-0.1.4}/examples/responses_endpoint.py +0 -0
  57. {courier_encode-0.1.2 → courier_encode-0.1.4}/examples/structured_output.py +0 -0
  58. {courier_encode-0.1.2 → courier_encode-0.1.4}/examples/tools_loop.py +0 -0
  59. {courier_encode-0.1.2 → courier_encode-0.1.4}/examples/whisper_transcribe.py +0 -0
  60. {courier_encode-0.1.2 → courier_encode-0.1.4}/src/encode/_config.py +0 -0
  61. {courier_encode-0.1.2 → courier_encode-0.1.4}/src/encode/_http.py +0 -0
  62. {courier_encode-0.1.2 → courier_encode-0.1.4}/src/encode/_schema.py +0 -0
  63. {courier_encode-0.1.2 → courier_encode-0.1.4}/src/encode/_streaming.py +0 -0
  64. {courier_encode-0.1.2 → courier_encode-0.1.4}/src/encode/_version.py +0 -0
  65. {courier_encode-0.1.2 → courier_encode-0.1.4}/src/encode/client.py +0 -0
  66. {courier_encode-0.1.2 → courier_encode-0.1.4}/src/encode/py.typed +0 -0
  67. {courier_encode-0.1.2 → courier_encode-0.1.4}/src/encode/responses.py +0 -0
  68. {courier_encode-0.1.2 → courier_encode-0.1.4}/src/encode/whisper.py +0 -0
  69. {courier_encode-0.1.2 → courier_encode-0.1.4}/tests/__init__.py +0 -0
  70. {courier_encode-0.1.2 → courier_encode-0.1.4}/tests/conftest.py +0 -0
  71. {courier_encode-0.1.2 → courier_encode-0.1.4}/tests/test_async.py +0 -0
  72. {courier_encode-0.1.2 → courier_encode-0.1.4}/tests/test_errors.py +0 -0
  73. {courier_encode-0.1.2 → courier_encode-0.1.4}/tests/test_messages.py +0 -0
  74. {courier_encode-0.1.2 → courier_encode-0.1.4}/tests/test_messages_obj.py +0 -0
  75. {courier_encode-0.1.2 → courier_encode-0.1.4}/tests/test_relay_chat.py +0 -0
  76. {courier_encode-0.1.2 → courier_encode-0.1.4}/tests/test_relay_responses.py +0 -0
  77. {courier_encode-0.1.2 → courier_encode-0.1.4}/tests/test_response_format.py +0 -0
  78. {courier_encode-0.1.2 → courier_encode-0.1.4}/tests/test_streaming.py +0 -0
  79. {courier_encode-0.1.2 → courier_encode-0.1.4}/tests/test_tool_loop.py +0 -0
  80. {courier_encode-0.1.2 → courier_encode-0.1.4}/tests/test_tools_schema.py +0 -0
  81. {courier_encode-0.1.2 → courier_encode-0.1.4}/tests/test_whisper.py +0 -0
  82. {courier_encode-0.1.2 → courier_encode-0.1.4}/uv.lock +0 -0
@@ -0,0 +1,105 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="AutoImportSettings">
4
+ <option name="autoReloadType" value="ALL" />
5
+ </component>
6
+ <component name="ChangeListManager">
7
+ <list default="true" id="9259bfb5-884c-4336-83fd-f640b45e88c5" name="Changes" comment="">
8
+ <change beforePath="$PROJECT_DIR$/README.md" beforeDir="false" afterPath="$PROJECT_DIR$/README.md" afterDir="false" />
9
+ <change beforePath="$PROJECT_DIR$/docs.md" beforeDir="false" afterPath="$PROJECT_DIR$/docs.md" afterDir="false" />
10
+ <change beforePath="$PROJECT_DIR$/docs/cookbook.md" beforeDir="false" afterPath="$PROJECT_DIR$/docs/cookbook.md" afterDir="false" />
11
+ <change beforePath="$PROJECT_DIR$/docs/intercept.md" beforeDir="false" afterPath="$PROJECT_DIR$/docs/intercept.md" afterDir="false" />
12
+ <change beforePath="$PROJECT_DIR$/docs/sessions.md" beforeDir="false" afterPath="$PROJECT_DIR$/docs/sessions.md" afterDir="false" />
13
+ <change beforePath="$PROJECT_DIR$/docs/tools.md" beforeDir="false" afterPath="$PROJECT_DIR$/docs/tools.md" afterDir="false" />
14
+ <change beforePath="$PROJECT_DIR$/src/encode/events.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/encode/events.py" afterDir="false" />
15
+ <change beforePath="$PROJECT_DIR$/src/encode/relay.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/encode/relay.py" afterDir="false" />
16
+ <change beforePath="$PROJECT_DIR$/src/encode/session.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/encode/session.py" afterDir="false" />
17
+ <change beforePath="$PROJECT_DIR$/src/encode/tools.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/encode/tools.py" afterDir="false" />
18
+ </list>
19
+ <option name="SHOW_DIALOG" value="false" />
20
+ <option name="HIGHLIGHT_CONFLICTS" value="true" />
21
+ <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
22
+ <option name="LAST_RESOLUTION" value="IGNORE" />
23
+ </component>
24
+ <component name="EmbeddingIndexingInfo">
25
+ <option name="cachedIndexableFilesCount" value="77" />
26
+ <option name="fileBasedEmbeddingIndicesEnabled" value="true" />
27
+ </component>
28
+ <component name="Git.Settings">
29
+ <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
30
+ </component>
31
+ <component name="McpProjectServerCommands">
32
+ <commands />
33
+ <urls />
34
+ </component>
35
+ <component name="ProjectColorInfo">{
36
+ &quot;associatedIndex&quot;: 8,
37
+ &quot;fromUser&quot;: false
38
+ }</component>
39
+ <component name="ProjectId" id="3DRfPMmybWPzhvemSx3K8mYqPeH" />
40
+ <component name="ProjectViewState">
41
+ <option name="hideEmptyMiddlePackages" value="true" />
42
+ <option name="showLibraryContents" value="true" />
43
+ </component>
44
+ <component name="PropertiesComponent">{
45
+ &quot;keyToString&quot;: {
46
+ &quot;ModuleVcsDetector.initialDetectionPerformed&quot;: &quot;true&quot;,
47
+ &quot;RunOnceActivity.MCP Project settings loaded&quot;: &quot;true&quot;,
48
+ &quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
49
+ &quot;RunOnceActivity.TerminalTabsStorage.copyFrom.TerminalArrangementManager.252&quot;: &quot;true&quot;,
50
+ &quot;RunOnceActivity.git.unshallow&quot;: &quot;true&quot;,
51
+ &quot;RunOnceActivity.typescript.service.memoryLimit.init&quot;: &quot;true&quot;,
52
+ &quot;codeWithMe.voiceChat.enabledByDefault&quot;: &quot;false&quot;,
53
+ &quot;com.intellij.ml.llm.matterhorn.ej.ui.settings.DefaultModelSelectionForGA.v1&quot;: &quot;true&quot;,
54
+ &quot;git-widget-placeholder&quot;: &quot;main&quot;,
55
+ &quot;junie.onboarding.icon.badge.shown&quot;: &quot;true&quot;,
56
+ &quot;last_opened_file_path&quot;: &quot;/Users/jacksonoaks/Documents/business/recursion_ai/encode&quot;,
57
+ &quot;node.js.detected.package.eslint&quot;: &quot;true&quot;,
58
+ &quot;node.js.detected.package.tslint&quot;: &quot;true&quot;,
59
+ &quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;,
60
+ &quot;node.js.selected.package.tslint&quot;: &quot;(autodetect)&quot;,
61
+ &quot;nodejs_package_manager_path&quot;: &quot;npm&quot;,
62
+ &quot;to.speed.mode.migration.done&quot;: &quot;true&quot;,
63
+ &quot;vue.rearranger.settings.migration&quot;: &quot;true&quot;
64
+ }
65
+ }</component>
66
+ <component name="SharedIndexes">
67
+ <attachedChunks>
68
+ <set>
69
+ <option value="bundled-js-predefined-d6986cc7102b-3bd3a6803838-JavaScript-PY-261.22158.340" />
70
+ <option value="bundled-python-sdk-b63d5a1f7c97-b61e75351b1f-com.jetbrains.pycharm.pro.sharedIndexes.bundled-PY-261.22158.340" />
71
+ </set>
72
+ </attachedChunks>
73
+ </component>
74
+ <component name="TaskManager">
75
+ <task active="true" id="Default" summary="Default task">
76
+ <changelist id="9259bfb5-884c-4336-83fd-f640b45e88c5" name="Changes" comment="" />
77
+ <created>1778249777914</created>
78
+ <option name="number" value="Default" />
79
+ <option name="presentableId" value="Default" />
80
+ <updated>1778249777914</updated>
81
+ <workItem from="1778249778942" duration="11940000" />
82
+ <workItem from="1778400115032" duration="568000" />
83
+ <workItem from="1778401424863" duration="35000" />
84
+ <workItem from="1778423372046" duration="273000" />
85
+ <workItem from="1778423984110" duration="32000" />
86
+ <workItem from="1778512211978" duration="598000" />
87
+ <workItem from="1778554267806" duration="2737000" />
88
+ <workItem from="1778562018820" duration="121000" />
89
+ <workItem from="1778562226220" duration="194000" />
90
+ <workItem from="1778562580231" duration="10000" />
91
+ <workItem from="1778562812770" duration="145000" />
92
+ <workItem from="1778563167441" duration="597000" />
93
+ <workItem from="1778563885595" duration="136000" />
94
+ <workItem from="1778564171039" duration="6000" />
95
+ <workItem from="1778565065245" duration="21000" />
96
+ <workItem from="1778566926702" duration="15000" />
97
+ <workItem from="1778567092312" duration="17000" />
98
+ <workItem from="1778617494707" duration="2069000" />
99
+ </task>
100
+ <servers />
101
+ </component>
102
+ <component name="TypeScriptGeneratedFilesManager">
103
+ <option name="version" value="3" />
104
+ </component>
105
+ </project>
@@ -0,0 +1,409 @@
1
+ Metadata-Version: 2.4
2
+ Name: courier-encode
3
+ Version: 0.1.4
4
+ Summary: Python SDK for OpenAI-compatible inference endpoints (Courier and friends) with auto tool-call loops, structured outputs, and Whisper.
5
+ Project-URL: Homepage, https://getcourier.ai
6
+ Project-URL: Documentation, https://getcourier.ai/docs
7
+ Project-URL: Repository, https://github.com/recursion-ai/encode
8
+ Author: Recursion AI
9
+ License: Apache License
10
+ Version 2.0, January 2004
11
+ http://www.apache.org/licenses/
12
+
13
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
14
+
15
+ 1. Definitions.
16
+
17
+ "License" shall mean the terms and conditions for use, reproduction,
18
+ and distribution as defined by Sections 1 through 9 of this document.
19
+
20
+ "Licensor" shall mean the copyright owner or entity authorized by
21
+ the copyright owner that is granting the License.
22
+
23
+ "Legal Entity" shall mean the union of the acting entity and all
24
+ other entities that control, are controlled by, or are under common
25
+ control with that entity. For the purposes of this definition,
26
+ "control" means (i) the power, direct or indirect, to cause the
27
+ direction or management of such entity, whether by contract or
28
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
29
+ outstanding shares, or (iii) beneficial ownership of such entity.
30
+
31
+ "You" (or "Your") shall mean an individual or Legal Entity
32
+ exercising permissions granted by this License.
33
+
34
+ "Source" form shall mean the preferred form for making modifications,
35
+ including but not limited to software source code, documentation
36
+ source, and configuration files.
37
+
38
+ "Object" form shall mean any form resulting from mechanical
39
+ transformation or translation of a Source form, including but
40
+ not limited to compiled object code, generated documentation,
41
+ and conversions to other media types.
42
+
43
+ "Work" shall mean the work of authorship, whether in Source or
44
+ Object form, made available under the License, as indicated by a
45
+ copyright notice that is included in or attached to the work
46
+ (an example is provided in the Appendix below).
47
+
48
+ "Derivative Works" shall mean any work, whether in Source or Object
49
+ form, that is based on (or derived from) the Work and for which the
50
+ editorial revisions, annotations, elaborations, or other modifications
51
+ represent, as a whole, an original work of authorship. For the purposes
52
+ of this License, Derivative Works shall not include works that remain
53
+ separable from, or merely link (or bind by name) to the interfaces of,
54
+ the Work and Derivative Works thereof.
55
+
56
+ "Contribution" shall mean any work of authorship, including
57
+ the original version of the Work and any modifications or additions
58
+ to that Work or Derivative Works thereof, that is intentionally
59
+ submitted to Licensor for inclusion in the Work by the copyright owner
60
+ or by an individual or Legal Entity authorized to submit on behalf of
61
+ the copyright owner. For the purposes of this definition, "submitted"
62
+ means any form of electronic, verbal, or written communication sent
63
+ to the Licensor or its representatives, including but not limited to
64
+ communication on electronic mailing lists, source code control systems,
65
+ and issue tracking systems that are managed by, or on behalf of, the
66
+ Licensor for the purpose of discussing and improving the Work, but
67
+ excluding communication that is conspicuously marked or otherwise
68
+ designated in writing by the copyright owner as "Not a Contribution."
69
+
70
+ "Contributor" shall mean Licensor and any individual or Legal Entity
71
+ on behalf of whom a Contribution has been received by Licensor and
72
+ subsequently incorporated within the Work.
73
+
74
+ 2. Grant of Copyright 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
+ copyright license to reproduce, prepare Derivative Works of,
78
+ publicly display, publicly perform, sublicense, and distribute the
79
+ Work and such Derivative Works in Source or Object form.
80
+
81
+ 3. Grant of Patent License. Subject to the terms and conditions of
82
+ this License, each Contributor hereby grants to You a perpetual,
83
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
84
+ (except as stated in this section) patent license to make, have made,
85
+ use, offer to sell, sell, import, and otherwise transfer the Work,
86
+ where such license applies only to those patent claims licensable
87
+ by such Contributor that are necessarily infringed by their
88
+ Contribution(s) alone or by combination of their Contribution(s)
89
+ with the Work to which such Contribution(s) was submitted. If You
90
+ institute patent litigation against any entity (including a
91
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
92
+ or a Contribution incorporated within the Work constitutes direct
93
+ or contributory patent infringement, then any patent licenses
94
+ granted to You under this License for that Work shall terminate
95
+ as of the date such litigation is filed.
96
+
97
+ 4. Redistribution. You may reproduce and distribute copies of the
98
+ Work or Derivative Works thereof in any medium, with or without
99
+ modifications, and in Source or Object form, provided that You
100
+ meet the following conditions:
101
+
102
+ (a) You must give any other recipients of the Work or
103
+ Derivative Works a copy of this License; and
104
+
105
+ (b) You must cause any modified files to carry prominent notices
106
+ stating that You changed the files; and
107
+
108
+ (c) You must retain, in the Source form of any Derivative Works
109
+ that You distribute, all copyright, patent, trademark, and
110
+ attribution notices from the Source form of the Work,
111
+ excluding those notices that do not pertain to any part of
112
+ the Derivative Works; and
113
+
114
+ (d) If the Work includes a "NOTICE" text file as part of its
115
+ distribution, then any Derivative Works that You distribute must
116
+ include a readable copy of the attribution notices contained
117
+ within such NOTICE file, excluding those notices that do not
118
+ pertain to any part of the Derivative Works, in at least one
119
+ of the following places: within a NOTICE text file distributed
120
+ as part of the Derivative Works; within the Source form or
121
+ documentation, if provided along with the Derivative Works; or,
122
+ within a display generated by the Derivative Works, if and
123
+ wherever such third-party notices normally appear. The contents
124
+ of the NOTICE file are for informational purposes only and
125
+ do not modify the License. You may add Your own attribution
126
+ notices within Derivative Works that You distribute, alongside
127
+ or as an addendum to the NOTICE text from the Work, provided
128
+ that such additional attribution notices cannot be construed
129
+ as modifying the License.
130
+
131
+ You may add Your own copyright statement to Your modifications and
132
+ may provide additional or different license terms and conditions
133
+ for use, reproduction, or distribution of Your modifications, or
134
+ for any such Derivative Works as a whole, provided Your use,
135
+ reproduction, and distribution of the Work otherwise complies with
136
+ the conditions stated in this License.
137
+
138
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
139
+ any Contribution intentionally submitted for inclusion in the Work
140
+ by You to the Licensor shall be under the terms and conditions of
141
+ this License, without any additional terms or conditions.
142
+ Notwithstanding the above, nothing herein shall supersede or modify
143
+ the terms of any separate license agreement you may have executed
144
+ with Licensor regarding such Contributions.
145
+
146
+ 6. Trademarks. This License does not grant permission to use the trade
147
+ names, trademarks, service marks, or product names of the Licensor,
148
+ except as required for reasonable and customary use in describing the
149
+ origin of the Work and reproducing the content of the NOTICE file.
150
+
151
+ 7. Disclaimer of Warranty. Unless required by applicable law or
152
+ agreed to in writing, Licensor provides the Work (and each
153
+ Contributor provides its Contributions) on an "AS IS" BASIS,
154
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
155
+ implied, including, without limitation, any warranties or conditions
156
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
157
+ PARTICULAR PURPOSE. You are solely responsible for determining the
158
+ appropriateness of using or redistributing the Work and assume any
159
+ risks associated with Your exercise of permissions under this License.
160
+
161
+ 8. Limitation of Liability. In no event and under no legal theory,
162
+ whether in tort (including negligence), contract, or otherwise,
163
+ unless required by applicable law (such as deliberate and grossly
164
+ negligent acts) or agreed to in writing, shall any Contributor be
165
+ liable to You for damages, including any direct, indirect, special,
166
+ incidental, or consequential damages of any character arising as a
167
+ result of this License or out of the use or inability to use the
168
+ Work (including but not limited to damages for loss of goodwill,
169
+ work stoppage, computer failure or malfunction, or any and all
170
+ other commercial damages or losses), even if such Contributor
171
+ has been advised of the possibility of such damages.
172
+
173
+ 9. Accepting Warranty or Additional Liability. While redistributing
174
+ the Work or Derivative Works thereof, You may choose to offer,
175
+ and charge a fee for, acceptance of support, warranty, indemnity,
176
+ or other liability obligations and/or rights consistent with this
177
+ License. However, in accepting such obligations, You may act only
178
+ on Your own behalf and on Your sole responsibility, not on behalf
179
+ of any other Contributor, and only if You agree to indemnify,
180
+ defend, and hold each Contributor harmless for any liability
181
+ incurred by, or claims asserted against, such Contributor by reason
182
+ of your accepting any such warranty or additional liability.
183
+
184
+ END OF TERMS AND CONDITIONS
185
+
186
+ APPENDIX: How to apply the Apache License to your work.
187
+
188
+ To apply the Apache License to your work, attach the following
189
+ boilerplate notice, with the fields enclosed by brackets "[]"
190
+ replaced with your own identifying information. (Don't include
191
+ the brackets!) The text should be enclosed in the appropriate
192
+ comment syntax for the file format. We also recommend that a
193
+ file or class name and description of purpose be included on the
194
+ same "printed page" as the copyright notice for easier
195
+ identification within third-party archives.
196
+
197
+ Copyright [yyyy] [name of copyright owner]
198
+
199
+ Licensed under the Apache License, Version 2.0 (the "License");
200
+ you may not use this file except in compliance with the License.
201
+ You may obtain a copy of the License at
202
+
203
+ http://www.apache.org/licenses/LICENSE-2.0
204
+
205
+ Unless required by applicable law or agreed to in writing, software
206
+ distributed under the License is distributed on an "AS IS" BASIS,
207
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
208
+ See the License for the specific language governing permissions and
209
+ limitations under the License.
210
+ License-File: LICENSE
211
+ Keywords: agents,courier,llm,openai,sdk,tool-calling,whisper
212
+ Classifier: Development Status :: 3 - Alpha
213
+ Classifier: Intended Audience :: Developers
214
+ Classifier: License :: OSI Approved :: Apache Software License
215
+ Classifier: Programming Language :: Python :: 3
216
+ Classifier: Programming Language :: Python :: 3.10
217
+ Classifier: Programming Language :: Python :: 3.11
218
+ Classifier: Programming Language :: Python :: 3.12
219
+ Classifier: Programming Language :: Python :: 3.13
220
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
221
+ Classifier: Typing :: Typed
222
+ Requires-Python: >=3.10
223
+ Requires-Dist: httpx>=0.27
224
+ Requires-Dist: pexpect>=4.9
225
+ Requires-Dist: pydantic>=2.7
226
+ Requires-Dist: python-dotenv>=1.0
227
+ Requires-Dist: typing-extensions>=4.10
228
+ Provides-Extra: dev
229
+ Requires-Dist: build>=1.2; extra == 'dev'
230
+ Requires-Dist: mypy>=1.10; extra == 'dev'
231
+ Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
232
+ Requires-Dist: pytest>=8.0; extra == 'dev'
233
+ Requires-Dist: respx>=0.21; extra == 'dev'
234
+ Requires-Dist: ruff>=0.5; extra == 'dev'
235
+ Description-Content-Type: text/markdown
236
+
237
+ # encode
238
+
239
+ > One Python entry-point for any OpenAI-compatible LLM, with an auto-agent loop, durable sessions, and the brain/hands/session primitives from Anthropic's [Managed Agents](https://www.anthropic.com/engineering/managed-agents) post baked in.
240
+
241
+ ```python
242
+ import encode
243
+
244
+ def get_weather(city: str) -> dict:
245
+ """Get weather by city."""
246
+ return {"city": city, "temp_f": 72}
247
+
248
+ out = encode.relay(
249
+ model="gpt-4o-mini",
250
+ messages=[{"role": "user", "content": "Weather in Denver?"}],
251
+ tools=[get_weather],
252
+ ).response
253
+
254
+ print(out.content) # "It's 72°F in Denver."
255
+ ```
256
+
257
+ That's the whole "hello world." The model called `get_weather`, encode dispatched it, fed the result back, and returned the final answer.
258
+
259
+ ## What encode is
260
+
261
+ A Python SDK for any OpenAI-compatible inference endpoint — Courier, OpenAI, vLLM, LM Studio, Ollama, Together, Groq, and more. One `relay()` function spans `/v1/chat/completions` and `/v1/responses`. Pass tools and it runs the loop to completion. Pass a `Session` and the run is durable. Pass a `Terminal` and your agent has a shell.
262
+
263
+ ## Why encode
264
+
265
+ - **Auto tool loop.** Drop a Python function in `tools=`; encode introspects the signature, builds the schema, runs the loop, and feeds results back. No decorators, no manual loop scaffolding.
266
+ - **Both endpoints, one API.** `relay()` auto-routes between `/v1/chat/completions` and `/v1/responses` — same handle, same tool loop, same intercept, same streaming consumer.
267
+ - **Sessions as Pydantic event logs.** Append-only, BYO storage. `session.model_dump()` to your DB; `Session.model_validate()` to resume — across processes, machines, or days.
268
+ - **Mid-loop context engineering.** Intercept callbacks can `append`, `insert`, `replace`, `edit_last_tool_result`, or `compact` the conversation that goes into the *next* iteration. Real context engineering in the harness, not just observation.
269
+ - **`ToolExecutor` seam.** Swap dispatch (local → remote → MCP → sub-agent) without touching the harness.
270
+ - **Terminal as a first-class primitive.** Persistent bash subprocess that retains cwd/env/venvs across calls. Wrap one in a closure and your agent has a shell.
271
+ - **Full sync/async parity.** Every helper has a `*_async` twin; async tool callables and async intercept callbacks just work.
272
+ - **Streaming with the loop intact.** Stream tokens *and* tool calls in real time across both endpoints.
273
+
274
+ ## 60-second tour
275
+
276
+ ```python
277
+ import json
278
+ import encode
279
+
280
+ # 1. Plain chat
281
+ encode.relay(
282
+ model="gpt-4o-mini",
283
+ messages=[{"role": "user", "content": "hi"}],
284
+ ).response.content
285
+
286
+ # 2. With a tool — auto-loop runs until the model stops calling tools
287
+ def lookup(q: str) -> dict:
288
+ """Look something up."""
289
+ return {"q": q, "answer": "42"}
290
+
291
+ encode.relay(
292
+ model="gpt-4o-mini",
293
+ messages=[{"role": "user", "content": "What's the meaning of life?"}],
294
+ tools=[lookup],
295
+ ).response.content
296
+
297
+ # 3. With a Session — durable, resumable, BYO persistence
298
+ session = encode.Session.open()
299
+ encode.relay(
300
+ model="gpt-4o-mini",
301
+ messages=[{"role": "user", "content": "remember: my name is Alex"}],
302
+ session=session,
303
+ ).response
304
+
305
+ # Persist anywhere — file, Postgres, Redis, S3...
306
+ open("/tmp/agent.json", "w").write(json.dumps(session.model_dump(), default=str))
307
+
308
+ # Resume anywhere
309
+ resumed = encode.Session.model_validate(json.loads(open("/tmp/agent.json").read()))
310
+ encode.relay(
311
+ model="gpt-4o-mini",
312
+ messages=[{"role": "user", "content": "what's my name?"}],
313
+ session=resumed,
314
+ ).response.content # → "Alex"
315
+ ```
316
+
317
+ ## Install
318
+
319
+ ```bash
320
+ pip install encode
321
+ ```
322
+
323
+ Python 3.10+. Configure with a `.env` (auto-loaded) or kwargs:
324
+
325
+ ```bash
326
+ # .env
327
+ ENCODE_API_KEY=sk-your-key
328
+ ENCODE_BASE_URL=https://api.openai.com/v1
329
+ ```
330
+
331
+ `OPENAI_API_KEY` / `OPENAI_BASE_URL` are also picked up if `ENCODE_*` aren't set.
332
+
333
+ ## What you can build
334
+
335
+ **Multi-turn chat with stateful `Messages`** — pass a `Messages` instance and it grows itself across `relay()` calls.
336
+
337
+ ```python
338
+ m = encode.Messages().system("Be brief.")
339
+ m.user("name three colors")
340
+ encode.relay(model="m", messages=m).response # m now has the assistant turn too
341
+ ```
342
+
343
+ **An agent that stops when it submits a final answer.**
344
+
345
+ ```python
346
+ def watcher(event):
347
+ if any(tc.name == "submit_final" for tc in event.tool_calls):
348
+ event.stop()
349
+
350
+ encode.relay(..., tools=[search, submit_final]).intercept(watcher).response
351
+ ```
352
+
353
+ **Mid-loop context compaction** — trim, summarize, redact, or rewrite history without subclassing anything.
354
+
355
+ ```python
356
+ def trim(event):
357
+ event.edit_last_tool_result(lambda c: c[:1000])
358
+
359
+ encode.relay(..., tools=[noisy_tool], on_intercept=trim).response
360
+ ```
361
+
362
+ **Auto tool discovery** — the model calls a `list_tools` bootstrap, an intercept registers the discovered tools on the session, the next iteration uses them.
363
+
364
+ ```python
365
+ session = encode.Session.open(tools=[list_tools])
366
+
367
+ def discover(event):
368
+ for tc in event.tool_calls:
369
+ if tc.name == "list_tools":
370
+ for spec in tc.result or []:
371
+ event.register_tool(IMPLS[spec["function"]["name"]])
372
+
373
+ encode.relay(model="m", messages=[...], session=session,
374
+ tools=session.tools, on_intercept=discover).response
375
+ ```
376
+
377
+ **A bash sandbox tool.**
378
+
379
+ ```python
380
+ class BashSandbox:
381
+ def __init__(self):
382
+ self._term = None
383
+ def as_tool(self):
384
+ sandbox = self
385
+ def bash(command: str) -> dict:
386
+ """Run a bash command in a persistent shell."""
387
+ self._term = self._term or encode.Terminal()
388
+ r = self._term.run(command, timeout=10.0)
389
+ return {"output": r.output, "exit_code": r.exit_code, "cwd": r.cwd}
390
+ return bash
391
+
392
+ encode.relay(..., tools=[BashSandbox().as_tool()]).response
393
+ ```
394
+
395
+ ## Docs
396
+
397
+ → [docs.md](./docs.md) is the entry point — concept map + a link grid into focused topic pages:
398
+
399
+ [quickstart](./docs/quickstart.md) · [concepts](./docs/concepts.md) · [relay()](./docs/relay.md) · [messages](./docs/messages.md) · [tools](./docs/tools.md) · [intercept](./docs/intercept.md) · [sessions](./docs/sessions.md) · [executors](./docs/executors.md) · [terminal](./docs/terminal.md) · [streaming](./docs/streaming.md) · [structured output](./docs/structured-output.md) · [whisper](./docs/whisper.md) · [async](./docs/async.md) · [errors](./docs/errors.md) · [cookbook](./docs/cookbook.md)
400
+
401
+ ## Status & compatibility
402
+
403
+ - Python 3.10+
404
+ - macOS / Linux for `Terminal` (pexpect-backed)
405
+ - OpenAI-compatible endpoints: OpenAI, [Courier](https://getcourier.ai), vLLM, LM Studio, Ollama, Together, Groq, and others
406
+
407
+ ## License
408
+
409
+ MIT