sfdc-agentforce-byoc-python-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 (38) hide show
  1. sfdc_agentforce_byoc_python_sdk-0.1.0/LICENSE +206 -0
  2. sfdc_agentforce_byoc_python_sdk-0.1.0/PKG-INFO +439 -0
  3. sfdc_agentforce_byoc_python_sdk-0.1.0/README.md +413 -0
  4. sfdc_agentforce_byoc_python_sdk-0.1.0/agentforce_byoc/__init__.py +26 -0
  5. sfdc_agentforce_byoc_python_sdk-0.1.0/agentforce_byoc/_http.py +142 -0
  6. sfdc_agentforce_byoc_python_sdk-0.1.0/agentforce_byoc/cli/__init__.py +8 -0
  7. sfdc_agentforce_byoc_python_sdk-0.1.0/agentforce_byoc/cli/commands.py +913 -0
  8. sfdc_agentforce_byoc_python_sdk-0.1.0/agentforce_byoc/cli/main.py +44 -0
  9. sfdc_agentforce_byoc_python_sdk-0.1.0/agentforce_byoc/client.py +224 -0
  10. sfdc_agentforce_byoc_python_sdk-0.1.0/agentforce_byoc/deploy_client.py +246 -0
  11. sfdc_agentforce_byoc_python_sdk-0.1.0/agentforce_byoc/gateway/__init__.py +26 -0
  12. sfdc_agentforce_byoc_python_sdk-0.1.0/agentforce_byoc/gateway/base.py +66 -0
  13. sfdc_agentforce_byoc_python_sdk-0.1.0/agentforce_byoc/gateway/mock_relay_client.py +54 -0
  14. sfdc_agentforce_byoc_python_sdk-0.1.0/agentforce_byoc/gateway/relay_client.py +394 -0
  15. sfdc_agentforce_byoc_python_sdk-0.1.0/agentforce_byoc/logging/__init__.py +20 -0
  16. sfdc_agentforce_byoc_python_sdk-0.1.0/agentforce_byoc/logging/formatter.py +96 -0
  17. sfdc_agentforce_byoc_python_sdk-0.1.0/agentforce_byoc/logging/logger.py +59 -0
  18. sfdc_agentforce_byoc_python_sdk-0.1.0/agentforce_byoc/runtime/__init__.py +21 -0
  19. sfdc_agentforce_byoc_python_sdk-0.1.0/agentforce_byoc/runtime/agentforce_runtime.py +47 -0
  20. sfdc_agentforce_byoc_python_sdk-0.1.0/agentforce_byoc/runtime/base.py +54 -0
  21. sfdc_agentforce_byoc_python_sdk-0.1.0/agentforce_byoc/runtime/mock_runtime.py +50 -0
  22. sfdc_agentforce_byoc_python_sdk-0.1.0/agentforce_byoc/schema_utils/__init__.py +35 -0
  23. sfdc_agentforce_byoc_python_sdk-0.1.0/agentforce_byoc/schema_utils/entry_func.py +48 -0
  24. sfdc_agentforce_byoc_python_sdk-0.1.0/agentforce_byoc/schema_utils/generator.py +694 -0
  25. sfdc_agentforce_byoc_python_sdk-0.1.0/agentforce_byoc/schema_utils/schema.py +79 -0
  26. sfdc_agentforce_byoc_python_sdk-0.1.0/agentforce_byoc/templates/__init__.py +4 -0
  27. sfdc_agentforce_byoc_python_sdk-0.1.0/agentforce_byoc/templates/agent/.dockerignore.template +51 -0
  28. sfdc_agentforce_byoc_python_sdk-0.1.0/agentforce_byoc/templates/agent/.gitignore.template +64 -0
  29. sfdc_agentforce_byoc_python_sdk-0.1.0/agentforce_byoc/templates/agent/.python-version.template +1 -0
  30. sfdc_agentforce_byoc_python_sdk-0.1.0/agentforce_byoc/templates/agent/Dockerfile.template +41 -0
  31. sfdc_agentforce_byoc_python_sdk-0.1.0/agentforce_byoc/templates/agent/Makefile.template +51 -0
  32. sfdc_agentforce_byoc_python_sdk-0.1.0/agentforce_byoc/templates/agent/README.md.template +358 -0
  33. sfdc_agentforce_byoc_python_sdk-0.1.0/agentforce_byoc/templates/agent/config.json.template +3 -0
  34. sfdc_agentforce_byoc_python_sdk-0.1.0/agentforce_byoc/templates/agent/entry_func.py.template +51 -0
  35. sfdc_agentforce_byoc_python_sdk-0.1.0/agentforce_byoc/templates/agent/main.py.template +149 -0
  36. sfdc_agentforce_byoc_python_sdk-0.1.0/agentforce_byoc/templates/agent/pyproject.toml.template +24 -0
  37. sfdc_agentforce_byoc_python_sdk-0.1.0/agentforce_byoc/templates/agent/schema.py.template +73 -0
  38. sfdc_agentforce_byoc_python_sdk-0.1.0/pyproject.toml +103 -0
@@ -0,0 +1,206 @@
1
+ Apache License Version 2.0
2
+
3
+ Copyright (c) 2026 Salesforce, Inc.
4
+ All rights reserved.
5
+
6
+ Apache License
7
+ Version 2.0, January 2004
8
+ http://www.apache.org/licenses/
9
+
10
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
11
+
12
+ 1. Definitions.
13
+
14
+ "License" shall mean the terms and conditions for use, reproduction,
15
+ and distribution as defined by Sections 1 through 9 of this document.
16
+
17
+ "Licensor" shall mean the copyright owner or entity authorized by
18
+ the copyright owner that is granting the License.
19
+
20
+ "Legal Entity" shall mean the union of the acting entity and all
21
+ other entities that control, are controlled by, or are under common
22
+ control with that entity. For the purposes of this definition,
23
+ "control" means (i) the power, direct or indirect, to cause the
24
+ direction or management of such entity, whether by contract or
25
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
26
+ outstanding shares, or (iii) beneficial ownership of such entity.
27
+
28
+ "You" (or "Your") shall mean an individual or Legal Entity
29
+ exercising permissions granted by this License.
30
+
31
+ "Source" form shall mean the preferred form for making modifications,
32
+ including but not limited to software source code, documentation
33
+ source, and configuration files.
34
+
35
+ "Object" form shall mean any form resulting from mechanical
36
+ transformation or translation of a Source form, including but
37
+ not limited to compiled object code, generated documentation,
38
+ and conversions to other media types.
39
+
40
+ "Work" shall mean the work of authorship, whether in Source or
41
+ Object form, made available under the License, as indicated by a
42
+ copyright notice that is included in or attached to the work
43
+ (an example is provided in the Appendix below).
44
+
45
+ "Derivative Works" shall mean any work, whether in Source or Object
46
+ form, that is based on (or derived from) the Work and for which the
47
+ editorial revisions, annotations, elaborations, or other modifications
48
+ represent, as a whole, an original work of authorship. For the purposes
49
+ of this License, Derivative Works shall not include works that remain
50
+ separable from, or merely link (or bind by name) to the interfaces of,
51
+ the Work and Derivative Works thereof.
52
+
53
+ "Contribution" shall mean any work of authorship, including
54
+ the original version of the Work and any modifications or additions
55
+ to that Work or Derivative Works thereof, that is intentionally
56
+ submitted to Licensor for inclusion in the Work by the copyright owner
57
+ or by an individual or Legal Entity authorized to submit on behalf of
58
+ the copyright owner. For the purposes of this definition, "submitted"
59
+ means any form of electronic, verbal, or written communication sent
60
+ to the Licensor or its representatives, including but not limited to
61
+ communication on electronic mailing lists, source code control systems,
62
+ and issue tracking systems that are managed by, or on behalf of, the
63
+ Licensor for the purpose of discussing and improving the Work, but
64
+ excluding communication that is conspicuously marked or otherwise
65
+ designated in writing by the copyright owner as "Not a Contribution."
66
+
67
+ "Contributor" shall mean Licensor and any individual or Legal Entity
68
+ on behalf of whom a Contribution has been received by Licensor and
69
+ subsequently incorporated within the Work.
70
+
71
+ 2. Grant of Copyright License. Subject to the terms and conditions of
72
+ this License, each Contributor hereby grants to You a perpetual,
73
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
74
+ copyright license to reproduce, prepare Derivative Works of,
75
+ publicly display, publicly perform, sublicense, and distribute the
76
+ Work and such Derivative Works in Source or Object form.
77
+
78
+ 3. Grant of Patent License. Subject to the terms and conditions of
79
+ this License, each Contributor hereby grants to You a perpetual,
80
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
81
+ (except as stated in this section) patent license to make, have made,
82
+ use, offer to sell, sell, import, and otherwise transfer the Work,
83
+ where such license applies only to those patent claims licensable
84
+ by such Contributor that are necessarily infringed by their
85
+ Contribution(s) alone or by combination of their Contribution(s)
86
+ with the Work to which such Contribution(s) was submitted. If You
87
+ institute patent litigation against any entity (including a
88
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
89
+ or a Contribution incorporated within the Work constitutes direct
90
+ or contributory patent infringement, then any patent licenses
91
+ granted to You under this License for that Work shall terminate
92
+ as of the date such litigation is filed.
93
+
94
+ 4. Redistribution. You may reproduce and distribute copies of the
95
+ Work or Derivative Works thereof in any medium, with or without
96
+ modifications, and in Source or Object form, provided that You
97
+ meet the following conditions:
98
+
99
+ (a) You must give any other recipients of the Work or
100
+ Derivative Works a copy of this License; and
101
+
102
+ (b) You must cause any modified files to carry prominent notices
103
+ stating that You changed the files; and
104
+
105
+ (c) You must retain, in the Source form of any Derivative Works
106
+ that You distribute, all copyright, patent, trademark, and
107
+ attribution notices from the Source form of the Work,
108
+ excluding those notices that do not pertain to any part of
109
+ the Derivative Works; and
110
+
111
+ (d) If the Work includes a "NOTICE" text file as part of its
112
+ distribution, then any Derivative Works that You distribute must
113
+ include a readable copy of the attribution notices contained
114
+ within such NOTICE file, excluding those notices that do not
115
+ pertain to any part of the Derivative Works, in at least one
116
+ of the following places: within a NOTICE text file distributed
117
+ as part of the Derivative Works; within the Source form or
118
+ documentation, if provided along with the Derivative Works; or,
119
+ within a display generated by the Derivative Works, if and
120
+ wherever such third-party notices normally appear. The contents
121
+ of the NOTICE file are for informational purposes only and
122
+ do not modify the License. You may add Your own attribution
123
+ notices within Derivative Works that You distribute, alongside
124
+ or as an addendum to the NOTICE text from the Work, provided
125
+ that such additional attribution notices cannot be construed
126
+ as modifying the License.
127
+
128
+ You may add Your own copyright statement to Your modifications and
129
+ may provide additional or different license terms and conditions
130
+ for use, reproduction, or distribution of Your modifications, or
131
+ for any such Derivative Works as a whole, provided Your use,
132
+ reproduction, and distribution of the Work otherwise complies with
133
+ the conditions stated in this License.
134
+
135
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
136
+ any Contribution intentionally submitted for inclusion in the Work
137
+ by You to the Licensor shall be under the terms and conditions of
138
+ this License, without any additional terms or conditions.
139
+ Notwithstanding the above, nothing herein shall supersede or modify
140
+ the terms of any separate license agreement you may have executed
141
+ with Licensor regarding such Contributions.
142
+
143
+ 6. Trademarks. This License does not grant permission to use the trade
144
+ names, trademarks, service marks, or product names of the Licensor,
145
+ except as required for reasonable and customary use in describing the
146
+ origin of the Work and reproducing the content of the NOTICE file.
147
+
148
+ 7. Disclaimer of Warranty. Unless required by applicable law or
149
+ agreed to in writing, Licensor provides the Work (and each
150
+ Contributor provides its Contributions) on an "AS IS" BASIS,
151
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
152
+ implied, including, without limitation, any warranties or conditions
153
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
154
+ PARTICULAR PURPOSE. You are solely responsible for determining the
155
+ appropriateness of using or redistributing the Work and assume any
156
+ risks associated with Your exercise of permissions under this License.
157
+
158
+ 8. Limitation of Liability. In no event and under no legal theory,
159
+ whether in tort (including negligence), contract, or otherwise,
160
+ unless required by applicable law (such as deliberate and grossly
161
+ negligent acts) or agreed to in writing, shall any Contributor be
162
+ liable to You for damages, including any direct, indirect, special,
163
+ incidental, or consequential damages of any character arising as a
164
+ result of this License or out of the use or inability to use the
165
+ Work (including but not limited to damages for loss of goodwill,
166
+ work stoppage, computer failure or malfunction, or any and all
167
+ other commercial damages or losses), even if such Contributor
168
+ has been advised of the possibility of such damages.
169
+
170
+ 9. Accepting Warranty or Additional Liability. While redistributing
171
+ the Work or Derivative Works thereof, You may choose to offer,
172
+ and charge a fee for, acceptance of support, warranty, indemnity,
173
+ or other liability obligations and/or rights consistent with this
174
+ License. However, in accepting such obligations, You may act only
175
+ on Your own behalf and on Your sole responsibility, not on behalf
176
+ of any other Contributor, and only if You agree to indemnify,
177
+ defend, and hold each Contributor harmless for any liability
178
+ incurred by, or claims asserted against, such Contributor by reason
179
+ of your accepting any such warranty or additional liability.
180
+
181
+ END OF TERMS AND CONDITIONS
182
+
183
+ APPENDIX: How to apply the Apache License to your work.
184
+
185
+ To apply the Apache License to your work, attach the following
186
+ boilerplate notice, with the fields enclosed by brackets "{}"
187
+ replaced with your own identifying information. (Don't include
188
+ the brackets!) The text should be enclosed in the appropriate
189
+ comment syntax for the file format. We also recommend that a
190
+ file or class name and description of purpose be included on the
191
+ same "printed page" as the copyright notice for easier
192
+ identification within third-party archives.
193
+
194
+ Copyright {yyyy} {name of copyright owner}
195
+
196
+ Licensed under the Apache License, Version 2.0 (the "License");
197
+ you may not use this file except in compliance with the License.
198
+ You may obtain a copy of the License at
199
+
200
+ http://www.apache.org/licenses/LICENSE-2.0
201
+
202
+ Unless required by applicable law or agreed to in writing, software
203
+ distributed under the License is distributed on an "AS IS" BASIS,
204
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
205
+ See the License for the specific language governing permissions and
206
+ limitations under the License.
@@ -0,0 +1,439 @@
1
+ Metadata-Version: 2.4
2
+ Name: sfdc-agentforce-byoc-python-sdk
3
+ Version: 0.1.0
4
+ Summary: Python SDK for Agentforce BYOC (Bring Your Own Code)
5
+ License: Apache-2.0
6
+ License-File: LICENSE
7
+ Keywords: agentforce,byoc,salesforce,sdk
8
+ Requires-Python: >=3.11,<4.0
9
+ Classifier: Development Status :: 4 - Beta
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: License :: OSI Approved :: Apache Software License
12
+ Classifier: Operating System :: OS Independent
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: Programming Language :: Python :: 3.14
18
+ Classifier: Programming Language :: Python :: 3.15
19
+ Requires-Dist: click (>=8.1.7,<9.0.0)
20
+ Requires-Dist: pydantic (>=2.0.0,<3.0.0)
21
+ Requires-Dist: pyyaml (>=6.0,<7.0)
22
+ Project-URL: Homepage, https://github.com/salesforce/agentforce-byoc-python-sdk
23
+ Project-URL: Repository, https://github.com/salesforce/agentforce-byoc-python-sdk
24
+ Description-Content-Type: text/markdown
25
+
26
+ # Agentforce BYOC Python SDK
27
+
28
+ Python SDK for building custom agents with Agentforce BYOC (Bring Your Own Code).
29
+
30
+ ## Overview
31
+
32
+ This SDK provides a straightforward way to build agents that integrate with Agentforce. Agents are simple Python functions that receive requests and return responses. The SDK handles relaying LLM calls through the Agentforce platform and structured logging.
33
+
34
+ ## Features
35
+
36
+ - **Functional API**: Write agents as simple functions
37
+ - **Agentforce BYOC runtime**: Relay LLM calls through the Agentforce platform
38
+ - **LLM Gateway Integration**: Call language models from the Agentforce runtime
39
+ - **Poetry Support**: Modern dependency management
40
+ - **CLI Tools**: Commands for project initialization, testing, and deployment
41
+
42
+ ## Requirements
43
+
44
+ - Python 3.11+
45
+ - Poetry for dependency management
46
+
47
+ ## Installation
48
+
49
+ ### From PyPI (available once published)
50
+
51
+ Once the package is published to PyPI, this is the official way to install the
52
+ SDK and its `agentforce` CLI:
53
+
54
+ ```bash
55
+ pip install sfdc-agentforce-byoc-python-sdk
56
+ ```
57
+
58
+ ### Development Setup
59
+
60
+ 1. Clone the repository:
61
+ ```bash
62
+ git clone <repository-url>
63
+ cd agentforce-byoc-python-sdk
64
+ ```
65
+
66
+ 2. Install dependencies:
67
+ ```bash
68
+ make setup
69
+ ```
70
+
71
+ 3. Verify installation:
72
+ ```bash
73
+ poetry run agentforce --version
74
+ ```
75
+
76
+ ## Quick Start
77
+
78
+ ### Create a New Agent
79
+
80
+ ```bash
81
+ agentforce init my-agent
82
+ cd my-agent
83
+ poetry install
84
+ ```
85
+
86
+ ### Write Your Agent
87
+
88
+ The generated `main.py` provides a working template. The entry point is a
89
+ function named `function` decorated with the SDK's schema helpers:
90
+
91
+ ```python
92
+ from agentforce_byoc import get_client, get_logger
93
+ from agentforce_byoc.schema_utils import entry_func, requestSchema, responseSchema
94
+
95
+ logger = get_logger(__name__)
96
+
97
+
98
+ @entry_func
99
+ @requestSchema(ExampleRequest)
100
+ @responseSchema(ExampleResponse)
101
+ def function(request: dict) -> dict:
102
+ """Entry point called by the Agentforce BYOC runtime."""
103
+ text = request.get("text", "")
104
+ if not text:
105
+ return {"result": "", "status": "error"}
106
+
107
+ # Relay a chat-generations call through the Agentforce Relay API. The
108
+ # tenant id, user id, and app context are read from the environment
109
+ # (SFDC_CORE_TENANT_ID / SFDC_USER_ID / SFDC_APP_CONTEXT), which the
110
+ # runtime injects.
111
+ client = get_client()
112
+ relay_response = client.call_llm_chat_generations(
113
+ parameter={"messages": [{"role": "user", "content": text}]},
114
+ )
115
+ return {"result": str(relay_response), "status": "success"}
116
+ ```
117
+
118
+ The template's `main()` builds a sample request (with a `text` placeholder to
119
+ fill in) and calls `function(...)` so you can test with `agentforce run`.
120
+
121
+ ### Test Your Agent
122
+
123
+ Run against the Agentforce BYOC runtime (set auth + tenant + user + app context
124
+ first — commands abort if unset):
125
+ ```bash
126
+ export ORG_JWT_TOKEN=<your-org-jwt>
127
+ export SFDC_CORE_TENANT_ID=core/<instance>-<fd>/<org-id>
128
+ export SFDC_USER_ID=<user-id>
129
+ export SFDC_APP_CONTEXT=<app-context>
130
+
131
+ agentforce run main.py
132
+ ```
133
+
134
+ ### Package and Deploy
135
+
136
+ ```bash
137
+ # Validate your agent
138
+ agentforce validate .
139
+
140
+ # Build end-to-end (validate -> run -> zip)
141
+ agentforce package .
142
+
143
+ # Register + upload to Agentforce BYOC in one step, then poll status
144
+ # (set all four identity env vars first; required)
145
+ export ORG_JWT_TOKEN=<jwt>
146
+ export SFDC_CORE_TENANT_ID=core/<instance>-<fd>/<org-id>
147
+ export SFDC_USER_ID=<user-id>
148
+ export SFDC_APP_CONTEXT=<app-context>
149
+ agentforce deploy --package-name "my-agent" --package-file my-agent-0.1.0.tar.gz
150
+ agentforce deploy-status --package-name "my-agent"
151
+ ```
152
+
153
+ ## API Reference
154
+
155
+ ### `get_client() -> Client`
156
+
157
+ Returns the singleton Client instance for relaying calls through the Agentforce Relay API.
158
+
159
+ ```python
160
+ from agentforce_byoc import get_client
161
+
162
+ client = get_client()
163
+ response = client.call_llm_generations(
164
+ parameter={"prompt": "What is AI?"},
165
+ )
166
+ ```
167
+
168
+ The client exposes one method per Relay function:
169
+ - `call_llm_generations(parameter)` — Relay function `llm`
170
+ - `call_llm_chat_generations(parameter)` — Relay function `llm_chat`
171
+
172
+ `parameter` is the raw request body and is passed through to the Relay API
173
+ unchanged. The tenant id, user id, and app context are read from the
174
+ environment (`SFDC_CORE_TENANT_ID` / `SFDC_USER_ID` / `SFDC_APP_CONTEXT`),
175
+ which the runtime injects in the managed sandbox. The endpoint URL is
176
+ `BYOC_PROXY_URL` as-is when it already ends in `/byoc/service` (as the runtime
177
+ injects it); otherwise `/byoc/service` is appended to the `BYOC_PROXY_URL` base
178
+ host (the same value `deploy` uses) or to `https://api.salesforce.com`.
179
+
180
+ **Runtime Selection:**
181
+ - **Agentforce BYOC runtime** (default): real Relay calls; org JWT from `ORG_JWT_TOKEN` (injected by the runtime)
182
+ - **Mock mode**: `AGENTFORCE_BYOC_MOCK` is set (truthy); org JWT supplied by the author (`ORG_JWT_TOKEN`)
183
+
184
+ ### `get_logger(name: str) -> Logger`
185
+
186
+ Returns a structured logger for your module.
187
+
188
+ ```python
189
+ from agentforce_byoc import get_logger
190
+
191
+ logger = get_logger(__name__)
192
+ logger.info("Processing request", extra={"user_id": "123"})
193
+ logger.error("Request failed", exc_info=True)
194
+ ```
195
+
196
+ ## State Management
197
+
198
+ Use module-level variables to maintain state across requests:
199
+
200
+ ```python
201
+ from agentforce_byoc import get_client, get_logger
202
+
203
+ logger = get_logger(__name__)
204
+
205
+ # Module-level state persists across function calls
206
+ _request_count = 0
207
+ _cache = {}
208
+
209
+ def function(request: dict) -> dict:
210
+ global _request_count
211
+ _request_count += 1
212
+
213
+ query = request.get("query", "")
214
+
215
+ # Check cache
216
+ if query in _cache:
217
+ return {"response": _cache[query], "cached": True}
218
+
219
+ # Relay an LLM generations call
220
+ client = get_client()
221
+ response = client.call_llm_generations(
222
+ parameter={"prompt": query},
223
+ )
224
+
225
+ # Update cache
226
+ _cache[query] = response
227
+
228
+ return {
229
+ "response": response,
230
+ "cached": False,
231
+ "request_number": _request_count
232
+ }
233
+ ```
234
+
235
+ ## CLI Commands
236
+
237
+ ### `agentforce init [directory]`
238
+
239
+ Initialize a new agent project.
240
+
241
+ ```bash
242
+ agentforce init my-agent
243
+ ```
244
+
245
+ ### `agentforce run [entrypoint]`
246
+
247
+ Run agent locally against the Agentforce BYOC runtime (requires the env vars).
248
+
249
+ ```bash
250
+ export ORG_JWT_TOKEN=<your-org-jwt>
251
+ export SFDC_CORE_TENANT_ID=core/<instance>-<fd>/<org-id>
252
+ export SFDC_USER_ID=<user-id>
253
+ export SFDC_APP_CONTEXT=<app-context>
254
+ agentforce run main.py
255
+ ```
256
+
257
+ ### `agentforce validate [path]`
258
+
259
+ Validate agent before deployment.
260
+
261
+ ```bash
262
+ agentforce validate .
263
+ ```
264
+
265
+ ### `agentforce package [path]`
266
+
267
+ Build end-to-end (validate → run → zip).
268
+
269
+ ```bash
270
+ agentforce package .
271
+ agentforce package --output my-agent.tar.gz
272
+ ```
273
+
274
+ Auth/identity for `run`, `deploy`, and `deploy-status` come from environment
275
+ variables — all four of `ORG_JWT_TOKEN`, `SFDC_CORE_TENANT_ID`
276
+ (`core/<instance>-<fd>/<org-id>`), `SFDC_USER_ID`, and `SFDC_APP_CONTEXT`. `run`
277
+ relays through the Agentforce service and `deploy`/`deploy-status` call the BYOC
278
+ API; both send the user id and app context as `x-sfdc-user-id` /
279
+ `x-sfdc-app-context`. If a required var is unset, the command aborts with an
280
+ `export` instruction. (They are not prompted: an org JWT exceeds the terminal's
281
+ ~1024-char line limit, so a typed prompt can't accept it.)
282
+
283
+ ### `agentforce deploy`
284
+
285
+ Register and upload a packaged agent to Agentforce BYOC. A single
286
+ `POST /byoc/upload/request` registers the package metadata (size, entry point,
287
+ max live duration) **and** returns a presigned upload URL; the CLI then PUTs the
288
+ archive to that URL.
289
+
290
+ ```bash
291
+ export ORG_JWT_TOKEN=<jwt>
292
+ export SFDC_CORE_TENANT_ID=core/<instance>-<fd>/<org-id>
293
+ export SFDC_USER_ID=<user-id>
294
+ export SFDC_APP_CONTEXT=<app-context>
295
+ agentforce deploy --package-name "my-agent" --package-file my-agent-0.1.0.tar.gz
296
+ ```
297
+
298
+ Options: `--package-name` and `--package-file` (required), plus `--entry-point`
299
+ (default `main.py`), `--version` (default `1.0`), and `--max-live-duration`
300
+ (default `300` seconds).
301
+
302
+ ### `agentforce deploy-status`
303
+
304
+ Poll deployment status (read-only). Calls `GET /byoc/upload/status` and reports
305
+ `registrationStatus` (is the package registered) and `uploadStatus` (has the
306
+ archive been uploaded). Registration happens during `deploy`; this command never
307
+ writes.
308
+
309
+ ```bash
310
+ agentforce deploy-status --package-name "my-agent" --version 1.0
311
+ ```
312
+
313
+ ## Architecture
314
+
315
+ ### Agent Interface
316
+
317
+ Agents are implemented as simple functions:
318
+
319
+ ```python
320
+ def function(request: dict) -> dict:
321
+ # Your code
322
+ return response
323
+ ```
324
+
325
+ The BYOC runtime calls this function for each request. The function receives a dictionary and returns a dictionary response
326
+
327
+ ### Runtime Selection
328
+
329
+ The SDK supports two runtimes, selected on first `get_client()` call:
330
+
331
+ 1. **Agentforce BYOC Runtime** (default)
332
+ - Real Relay API calls authenticated with the org JWT
333
+ - Org JWT read from `ORG_JWT_TOKEN` (injected by the runtime)
334
+ - Tenant id, user id, and app context read from `SFDC_CORE_TENANT_ID` /
335
+ `SFDC_USER_ID` / `SFDC_APP_CONTEXT` (injected by the runtime); endpoint
336
+ URL from `BYOC_PROXY_URL` (as-is if it ends in `/byoc/service`, else
337
+ with `/byoc/service` appended), else production + `/byoc/service`
338
+
339
+ 2. **Mock Mode**: `AGENTFORCE_BYOC_MOCK` env var is set (truthy)
340
+ - Same relay behavior, with the org JWT supplied by the author
341
+ - JWT from the `MockRelayGatewayClient(org_jwt=...)` arg or `ORG_JWT_TOKEN`
342
+ - Selected via the env var (there is no CLI flag for it)
343
+
344
+ ### Code Portability
345
+
346
+ Agent code works across both runtimes without modification:
347
+
348
+ ```python
349
+ # This code works in both runtimes
350
+ def function(request: dict) -> dict:
351
+ client = get_client() # Selects runtime
352
+ return client.call_llm_generations(...)
353
+ ```
354
+
355
+ ## Examples
356
+
357
+ The `examples/` directory contains working examples:
358
+
359
+ - **01_basic_agent.py** - Minimal functional agent
360
+ - **02_llm_agent.py** - LLM Gateway integration
361
+ - **03_sentiment_analysis.py** - Sentiment analysis use case
362
+ - **04_stateful_agent.py** - State management patterns
363
+
364
+ Run any example directly. Examples that call the relay need `ORG_JWT_TOKEN`,
365
+ `SFDC_CORE_TENANT_ID`, `SFDC_USER_ID`, and `SFDC_APP_CONTEXT` exported;
366
+ `01_basic_agent.py` does not call the relay and runs without credentials.
367
+
368
+ ```bash
369
+ export ORG_JWT_TOKEN=<your-org-jwt>
370
+ export SFDC_CORE_TENANT_ID=core/<instance>-<fd>/<org-id>
371
+ export SFDC_USER_ID=<user-id>
372
+ export SFDC_APP_CONTEXT=<app-context>
373
+ python examples/01_basic_agent.py
374
+ python examples/02_llm_agent.py
375
+ python examples/03_sentiment_analysis.py
376
+ ```
377
+
378
+ See [examples/README.md](examples/README.md) for detailed documentation.
379
+
380
+ ## Development
381
+
382
+ ### Project Structure
383
+
384
+ ```
385
+ agentforce-byoc-python-sdk/
386
+ ├── agentforce_byoc/ # Main package
387
+ │ ├── client.py # Client with runtime selection
388
+ │ ├── _http.py # Stdlib HTTP helper (preserves header casing)
389
+ │ ├── deploy_client.py # /byoc/upload/request + upload/status client
390
+ │ ├── runtime/ # Runtime providers
391
+ │ │ ├── mock_runtime.py # Mock provider
392
+ │ │ ├── agentforce_runtime.py # Agentforce provider (default)
393
+ │ │ └── base.py # Base provider interface
394
+ │ ├── gateway/ # Relay gateway clients
395
+ │ │ ├── relay_client.py # Agentforce relay client
396
+ │ │ ├── mock_relay_client.py # Mock relay client
397
+ │ │ └── base.py # Base interface
398
+ │ ├── schema_utils/ # entry_func / requestSchema / responseSchema
399
+ │ ├── logging/ # Structured logging
400
+ │ ├── cli/ # CLI commands
401
+ │ └── templates/ # Project templates
402
+ ├── examples/ # Working examples
403
+ ├── tests/ # Test suite
404
+ ├── pyproject.toml # Poetry configuration
405
+ └── README.md # This file
406
+ ```
407
+
408
+ ### Running Tests
409
+
410
+ ```bash
411
+ poetry run pytest
412
+ poetry run pytest --cov=agentforce_byoc
413
+ ```
414
+
415
+ ### Code Quality
416
+
417
+ ```bash
418
+ make format # black + isort
419
+ make lint # pre-commit: black, isort, ruff, codespell, license header, mypy
420
+ ```
421
+
422
+ ## Contributing
423
+
424
+ Contributions are welcome. See [CONTRIBUTING.md](CONTRIBUTING.md) for setup, the
425
+ development workflow, how to write tests, and the contributor/reviewer/trusted-committer
426
+ roles. Architecture and design notes live in [ARCHITECTURE.md](ARCHITECTURE.md).
427
+
428
+ ## Support
429
+
430
+ - **Questions / discussion**: start a [GitHub Discussion](https://github.com/salesforce/agentforce-byoc-python-sdk/discussions).
431
+ - **Bugs / feature requests**: file a [GitHub Issue](https://github.com/salesforce/agentforce-byoc-python-sdk/issues).
432
+ - **Security vulnerabilities**: follow [SECURITY.md](SECURITY.md) — please don't open a public issue for security reports.
433
+
434
+ ## License & Terms of Use
435
+
436
+ This project is licensed under the [Apache License 2.0](LICENSE).
437
+
438
+ Use of this project with Salesforce is subject to the [Terms of Use](TERMS_OF_USE.md).
439
+