agno-photon 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.
- agno_photon-0.1.0/.gitignore +8 -0
- agno_photon-0.1.0/LICENSE +202 -0
- agno_photon-0.1.0/PKG-INFO +253 -0
- agno_photon-0.1.0/README.md +222 -0
- agno_photon-0.1.0/pyproject.toml +81 -0
- agno_photon-0.1.0/src/agno_photon/__init__.py +28 -0
- agno_photon-0.1.0/src/agno_photon/_api.py +575 -0
- agno_photon-0.1.0/src/agno_photon/_attachments.py +154 -0
- agno_photon-0.1.0/src/agno_photon/_confine.py +125 -0
- agno_photon-0.1.0/src/agno_photon/_ledger.py +189 -0
- agno_photon-0.1.0/src/agno_photon/_media.py +140 -0
- agno_photon-0.1.0/src/agno_photon/_reply.py +132 -0
- agno_photon-0.1.0/src/agno_photon/_results.py +132 -0
- agno_photon-0.1.0/src/agno_photon/agentos.py +245 -0
- agno_photon-0.1.0/src/agno_photon/client.py +66 -0
- agno_photon-0.1.0/src/agno_photon/delivery.py +53 -0
- agno_photon-0.1.0/src/agno_photon/events.py +153 -0
- agno_photon-0.1.0/src/agno_photon/models.py +43 -0
- agno_photon-0.1.0/src/agno_photon/py.typed +0 -0
- agno_photon-0.1.0/src/agno_photon/responder.py +286 -0
- agno_photon-0.1.0/src/agno_photon/stream.py +385 -0
- agno_photon-0.1.0/src/agno_photon/toolkit.py +567 -0
- agno_photon-0.1.0/tests/conftest.py +59 -0
- agno_photon-0.1.0/tests/support.py +385 -0
- agno_photon-0.1.0/tests/test_agentos.py +211 -0
- agno_photon-0.1.0/tests/test_attachments.py +316 -0
- agno_photon-0.1.0/tests/test_client.py +98 -0
- agno_photon-0.1.0/tests/test_events.py +117 -0
- agno_photon-0.1.0/tests/test_reach.py +258 -0
- agno_photon-0.1.0/tests/test_reply_scope.py +195 -0
- agno_photon-0.1.0/tests/test_responder.py +441 -0
- agno_photon-0.1.0/tests/test_sender.py +168 -0
- agno_photon-0.1.0/tests/test_stream.py +369 -0
- agno_photon-0.1.0/tests/test_toolkit.py +451 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright 2026 Something Great Inc.
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: agno-photon
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Photon messaging for Agno agents: iMessage, SMS, WhatsApp, email and Telegram tools, inbound replies, and an AgentOS interface.
|
|
5
|
+
Project-URL: Repository, https://github.com/photon-hq/agno
|
|
6
|
+
Project-URL: Documentation, https://photon.codes/docs
|
|
7
|
+
Author: Photon
|
|
8
|
+
License-Expression: Apache-2.0
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Keywords: agents,agno,imessage,photon,sms,telegram,whatsapp
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
18
|
+
Classifier: Typing :: Typed
|
|
19
|
+
Requires-Python: >=3.11
|
|
20
|
+
Requires-Dist: agno<4,>=3.2.1
|
|
21
|
+
Requires-Dist: aiohttp<4,>=3.11
|
|
22
|
+
Requires-Dist: httpx<1,>=0.28.1
|
|
23
|
+
Requires-Dist: photonhq-api<0.10,>=0.9.0
|
|
24
|
+
Requires-Dist: pillow-heif>=1.1
|
|
25
|
+
Requires-Dist: pillow>=11.1
|
|
26
|
+
Requires-Dist: pydantic<3,>=2.13.5
|
|
27
|
+
Requires-Dist: python-socketio[asyncio-client]<6,>=5.11
|
|
28
|
+
Provides-Extra: agentos
|
|
29
|
+
Requires-Dist: agno[os]<4,>=3.2.1; extra == 'agentos'
|
|
30
|
+
Description-Content-Type: text/markdown
|
|
31
|
+
|
|
32
|
+
# agno-photon
|
|
33
|
+
|
|
34
|
+
Connect [Agno](https://github.com/agno-agi/agno) agents to the people who message your [Photon](https://photon.codes) lines over iMessage, SMS, WhatsApp, email, and Telegram.
|
|
35
|
+
|
|
36
|
+
The package has three parts, and you can use each one on its own:
|
|
37
|
+
|
|
38
|
+
| Part | What it does | Needs a public URL |
|
|
39
|
+
| --- | --- | --- |
|
|
40
|
+
| `PhotonTools` | An Agno toolkit: the agent finds a person, opens a conversation, sends messages and files, and reads history. | No |
|
|
41
|
+
| `PhotonEventStream` + `PhotonResponder` | Receive the messages people send and answer each one with an Agent, Team, or Workflow, in any asyncio program. | No |
|
|
42
|
+
| `agno_photon.agentos.PhotonInterface` | The same answering loop as an AgentOS interface, over the event stream or a signed webhook. | Only for the webhook transport |
|
|
43
|
+
|
|
44
|
+
## Install
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
pip install agno-photon # tools, event stream, responder
|
|
48
|
+
pip install "agno-photon[agentos]" # adds the AgentOS interface
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Python 3.11 or later, with `agno>=3.2.1,<4`.
|
|
52
|
+
|
|
53
|
+
## Configure
|
|
54
|
+
|
|
55
|
+
Create a project and an API key in the Photon dashboard, then connect a line.
|
|
56
|
+
|
|
57
|
+
| Variable | Required | Meaning |
|
|
58
|
+
| --- | --- | --- |
|
|
59
|
+
| `PHOTON_PROJECT_ID` | Yes | The project id, `pho_prj_...`. |
|
|
60
|
+
| `PHOTON_API_KEY` | Yes | A project API key, `pho_sk_...`. |
|
|
61
|
+
| `PHOTON_AGENT_USER_ID` | No | The agent user that sends. By default each space uses the project's agent user in that space, which the package finds by reading the project's users on that platform once per process; Photon cannot filter users by kind, so set this when the project has many contacts. |
|
|
62
|
+
| `PHOTON_API_URL` | No | API base URL. Defaults to `https://api.photon.codes`. |
|
|
63
|
+
| `PHOTON_WEBHOOK_SECRET` | Webhook only | The signing secret of the webhook destination, `whsec_...`. |
|
|
64
|
+
|
|
65
|
+
Every variable can also be passed in code: `PhotonClient(project_id=..., auth=...)`. `auth` takes an API key or a function that returns a bearer token; the function runs before every request, so it can refresh the token.
|
|
66
|
+
|
|
67
|
+
On the free shared iMessage line, add the phone number or email address your iMessage uses, then text the line first: a shared line cannot start a conversation. A shared line also rejects text and an attachment in one message, so `PhotonTools` tells the model to send them separately.
|
|
68
|
+
|
|
69
|
+
## Send messages with `PhotonTools`
|
|
70
|
+
|
|
71
|
+
```python
|
|
72
|
+
from agno.agent import Agent
|
|
73
|
+
from agno.models.openai import OpenAIResponses
|
|
74
|
+
from agno_photon import PhotonTools
|
|
75
|
+
|
|
76
|
+
agent = Agent(
|
|
77
|
+
model=OpenAIResponses(id="gpt-5.6-luna"),
|
|
78
|
+
tools=[PhotonTools(requires_confirmation_tools=["send_message"])],
|
|
79
|
+
)
|
|
80
|
+
agent.print_response("Text +14155550100 on iMessage: 'Your order is ready.'")
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
The toolkit fills in what the model should not have to know: the project's agent user, the participants Photon requires, and an idempotency key for each send, so a request the HTTP client retries is delivered once. When the agent replies to an inbound message (see below), the key comes from that event and the message content, so a redelivered event does not send the same reply twice.
|
|
84
|
+
|
|
85
|
+
| Tools | Enabled |
|
|
86
|
+
| --- | --- |
|
|
87
|
+
| `create_or_get_user`, `create_or_get_space`, `send_message`, `get_message`, `list_messages` | By default (`PhotonTools.DEFAULT_TOOLS`) |
|
|
88
|
+
| `get_user`, `get_space`, `list_spaces`, `get_attachment`, `download_attachment`, `mark_message_read`, `set_space_typing` | On request; `PhotonTools.ALL_TOOLS` lists every tool |
|
|
89
|
+
|
|
90
|
+
`include_tools` is the complete list of tools to enable, for example `include_tools=[*PhotonTools.DEFAULT_TOOLS, "mark_message_read"]`. Every tool has a sync and an async version, and every tool returns JSON. A failed call returns `{"error": {"code": ..., "message": ..., "hint": ...}}`; `code` is Photon's error code, or one of this package's codes such as `TRANSPORT_ERROR` or `INVALID_INPUT`.
|
|
91
|
+
|
|
92
|
+
Email goes out from an address on the domain connected in the dashboard. Photon only knows an address as a sender after its first use, so create it once before the agent's first email: `PhotonTools().create_or_get_user("email", "agent@your-domain.com")`.
|
|
93
|
+
|
|
94
|
+
### Attachments
|
|
95
|
+
|
|
96
|
+
An agent that answers inbound messages talks to strangers, so the toolkit limits where `send_message` may read files from:
|
|
97
|
+
|
|
98
|
+
| Source | Default | How to widen |
|
|
99
|
+
| --- | --- | --- |
|
|
100
|
+
| Local files | Only `attachment_dir`, where `download_attachment` saves files, so the agent can forward a file it received. While answering a message, only files of that conversation (see below). | `attachment_roots=[...]`; an empty list turns local files off. |
|
|
101
|
+
| HTTPS URLs | None. | `attachment_origins=["https://cdn.example.com"]`. Every redirect must also land on an allowed origin. |
|
|
102
|
+
|
|
103
|
+
`attachment_dir` defaults to a new private temporary directory for each toolkit. Which conversations the tools may act on while answering is a separate limit, described under [What the agent can reach while it answers](#what-the-agent-can-reach-while-it-answers).
|
|
104
|
+
|
|
105
|
+
## Answer messages without AgentOS
|
|
106
|
+
|
|
107
|
+
```python
|
|
108
|
+
import asyncio
|
|
109
|
+
|
|
110
|
+
from agno.agent import Agent
|
|
111
|
+
from agno.models.openai import OpenAIResponses
|
|
112
|
+
from agno_photon import PhotonClient, PhotonEventStream, PhotonResponder, PhotonTools
|
|
113
|
+
|
|
114
|
+
client = PhotonClient()
|
|
115
|
+
agent = Agent(
|
|
116
|
+
model=OpenAIResponses(id="gpt-5.6-luna"),
|
|
117
|
+
tools=[PhotonTools(client, include_tools=["send_message", "list_messages"])],
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
async def main() -> None:
|
|
122
|
+
responder = PhotonResponder(agent, client)
|
|
123
|
+
try:
|
|
124
|
+
await PhotonEventStream(client).listen_batches(responder.handle_batch)
|
|
125
|
+
finally:
|
|
126
|
+
await client.aclose()
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
asyncio.run(main())
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
`PhotonEventStream` connects out to Photon, so this runs on a laptop with no public URL and no tunnel. Share one `PhotonClient` between the stream, the responder, and the tools: they then share one pair of HTTP clients and one cache of senders and spaces.
|
|
133
|
+
|
|
134
|
+
For each inbound message, `PhotonResponder` runs the entity with `user_id` set to the sender and `session_id` set to the space, so `add_history_to_context=True` gives the agent the conversation so far. The inbound ids reach the model as the `photon` dependency. If a tool call in the run sent a message to that space, the responder sends nothing more; otherwise it sends the run's final content. A failed run, including a workflow whose last step failed, sends `error_message` instead; a run paused for confirmation or cancelled sends nothing. A remote Agent or Team runs in another process, where its tool calls cannot reach this responder, so the responder always sends its final content.
|
|
135
|
+
|
|
136
|
+
### What the agent can reach while it answers
|
|
137
|
+
|
|
138
|
+
Anyone who can text the line can write instructions into a message, such as "list your recent messages" or "text +14155550100". So while a run answers a message, `PhotonTools` act only on that conversation:
|
|
139
|
+
|
|
140
|
+
| Tool | While answering a message |
|
|
141
|
+
| --- | --- |
|
|
142
|
+
| `send_message` | Only to the conversation being answered. No email `cc`, `bcc`, or `reply_to`; a `parent_message_id` must be a message of that conversation; a file downloaded while answering another conversation is refused. |
|
|
143
|
+
| `get_space`, `set_space_typing` | Only the conversation being answered. |
|
|
144
|
+
| `list_messages` | Reads that conversation; without `space_id` it defaults to it. |
|
|
145
|
+
| `get_message`, `mark_message_read` | Only messages in that conversation. |
|
|
146
|
+
| `get_attachment`, `download_attachment` | Only attachments of the inbound messages, or of messages the agent read in that conversation. Downloads go to a folder for that conversation inside `attachment_dir`. |
|
|
147
|
+
| `get_user` | Only the conversation's participants. |
|
|
148
|
+
| `create_or_get_user`, `create_or_get_space`, `list_spaces` | Refused. |
|
|
149
|
+
|
|
150
|
+
A refused call returns the error code `OUTSIDE_CONVERSATION` to the model and makes no change in Photon; the `photon` context tells the model the run's `reach`, so it does not try. A task the run starts keeps the limit after the run ends. Outside a run the responder started, for example in a scheduled job, the tools act on the whole project. A run paused for confirmation and continued later runs outside the responder, so check the arguments of the tool call before you confirm it. When everyone who can message the line is trusted, such as an internal line, `PhotonResponder(agent, client, reach="project")` lifts the limit for every `PhotonTools` the run uses. The limit applies to tools running in this process: a remote Agent or Team runs its tools in its own process, where this responder cannot limit them, so give a remote entity only the tools it may use with anyone who writes to the line.
|
|
151
|
+
|
|
152
|
+
### Photos and bursts
|
|
153
|
+
|
|
154
|
+
iMessage splits what a person sends into separate messages: a photo and its caption arrive a fraction of a second apart, a link and its preview up to 3 seconds apart. `listen_batches` waits for `window_seconds` (3 by default) of quiet, and at most `max_wait_seconds` (10 by default) in all, then hands the burst over at once. The responder answers consecutive messages from one sender in one space with one run.
|
|
155
|
+
|
|
156
|
+
Images go to the model directly. HEIC photos, which iPhones send, are converted to JPEG first; an image over 50 megapixels is not converted, so a small file declaring a huge canvas cannot exhaust memory. Any other file, such as a PDF or a voice note, reaches the model as a note with the attachment id, because which files a model accepts differs by provider; give the agent `download_attachment` and a tool that reads the file if it needs the content.
|
|
157
|
+
|
|
158
|
+
### Delivery and restarts
|
|
159
|
+
|
|
160
|
+
A handler tells the stream what happened to each event with a `Disposition`:
|
|
161
|
+
|
|
162
|
+
| Disposition | Meaning | What the stream does |
|
|
163
|
+
| --- | --- | --- |
|
|
164
|
+
| `HANDLED` | Done. | Moves the cursor past it. |
|
|
165
|
+
| `SKIPPED` | Will never be handled, such as an event type the handler ignores. | Moves the cursor past it. |
|
|
166
|
+
| `RETRY` | Failed for now. | Delivers it again, up to 3 attempts with backoff, then logs an error and skips it. |
|
|
167
|
+
|
|
168
|
+
A handler that raises counts as `RETRY`; one that returns `None` counts as `HANDLED`. Each space runs in order, with up to `max_concurrent_spaces` spaces (8 by default) active at once. The responder never runs the entity twice for one event: when Photon rejects a computed reply for a transient reason, the retry sends the same reply again.
|
|
169
|
+
|
|
170
|
+
The cursor is the sequence of the last event the stream may skip on reconnect. The default `MemoryCursorStore` starts again from new events after a restart. To resume where the process stopped, pass a store that persists it. Both methods are awaited on the event loop, and `save` runs after every batch of finished events, so do the I/O asynchronously or in a thread:
|
|
171
|
+
|
|
172
|
+
```python
|
|
173
|
+
import asyncio
|
|
174
|
+
from pathlib import Path
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
class FileCursorStore:
|
|
178
|
+
def __init__(self, path: str) -> None:
|
|
179
|
+
self.path = Path(path)
|
|
180
|
+
|
|
181
|
+
async def load(self) -> int:
|
|
182
|
+
text = await asyncio.to_thread(lambda: self.path.read_text() if self.path.exists() else "0")
|
|
183
|
+
return int(text)
|
|
184
|
+
|
|
185
|
+
async def save(self, seq: int) -> None:
|
|
186
|
+
await asyncio.to_thread(self.path.write_text, str(seq))
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
stream = PhotonEventStream(client, cursor_store=FileCursorStore("photon.cursor"))
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
Photon replays only events it still retains after the saved cursor.
|
|
193
|
+
|
|
194
|
+
## Serve from AgentOS
|
|
195
|
+
|
|
196
|
+
```python
|
|
197
|
+
from agno.agent import Agent
|
|
198
|
+
from agno.models.openai import OpenAIResponses
|
|
199
|
+
from agno.os import AgentOS
|
|
200
|
+
from agno_photon.agentos import PhotonInterface
|
|
201
|
+
|
|
202
|
+
assistant = Agent(id="assistant", model=OpenAIResponses(id="gpt-5.6-luna"))
|
|
203
|
+
agent_os = AgentOS(agents=[assistant], interfaces=[PhotonInterface(agent=assistant)])
|
|
204
|
+
app = agent_os.get_app()
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
Pass exactly one of `agent`, `team`, or `workflow`. The interface runs the responder described above over one of two transports:
|
|
208
|
+
|
|
209
|
+
| | `EventStreamTransport()` (default) | `WebhookTransport()` |
|
|
210
|
+
| --- | --- | --- |
|
|
211
|
+
| Public URL | Not needed. | HTTPS; Photon does not deliver to localhost. |
|
|
212
|
+
| Route | None. AgentOS startup waits until the stream has subscribed. | `POST /photon/webhook`, which checks the signature and that the event belongs to the client's project. |
|
|
213
|
+
| Restart | Resumes from a persistent `cursor_store`. | Best effort: the route answers 204 before the run, so work in flight is lost if the process exits. Photon does not deliver the event again after the 204, so a reply Photon cannot take yet is retried in the process, up to 3 attempts. |
|
|
214
|
+
| Options | `cursor_store`, `batch_window_seconds`, `batch_max_wait_seconds`, `max_concurrent_spaces` | `secret`, defaulting to `PHOTON_WEBHOOK_SECRET` |
|
|
215
|
+
|
|
216
|
+
For the webhook, add a destination `https://<your-host>/photon/webhook` for `message.received` in the dashboard and set its signing secret. The route answers 401 to a bad signature and 400 to an event it cannot read; Photon does not retry either. See [webhook delivery and retries](https://photon.codes/docs/beta/message-delivery/webhook).
|
|
217
|
+
|
|
218
|
+
Other options: `reach` limits the tools to the conversation being answered (`"conversation"`, the default) or lets them act on the whole project (`"project"`), as described in [What the agent can reach while it answers](#what-the-agent-can-reach-while-it-answers); `error_message` is sent when a run fails (`None` sends nothing); `typing_indicator=True` shows a typing indicator during the run, which Photon stores as a message in the space and which a shared iMessage line can reject; `prefix` and `tags` set the route prefix and OpenAPI tags. An interface closes its client on shutdown only if it created that client.
|
|
219
|
+
|
|
220
|
+
## Photon API version
|
|
221
|
+
|
|
222
|
+
Every request sends `Photon-Version: 2026-07-01`, and the event stream subscribes with the same version, so the shapes this package reads do not change when the project's default version changes. A release of this package moves to a newer version deliberately.
|
|
223
|
+
|
|
224
|
+
## Public API
|
|
225
|
+
|
|
226
|
+
`agno_photon` exports `PhotonClient`, `TokenProvider`, `PhotonTools`, `PhotonEventStream`, `PhotonResponder`, `PhotonEvent`, `PhotonMessage`, `parse_webhook`, `Disposition`, `EventHandler`, `BatchHandler`, `CursorStore`, and `MemoryCursorStore`. `agno_photon.agentos` exports `PhotonInterface`, `EventStreamTransport`, and `WebhookTransport`. Modules and attributes whose names start with an underscore are internal and may change in any release.
|
|
227
|
+
|
|
228
|
+
## Examples
|
|
229
|
+
|
|
230
|
+
The [`examples`](examples) directory has a runnable script for each part. They use OpenAI models, so install `openai` and set `OPENAI_API_KEY` as well.
|
|
231
|
+
|
|
232
|
+
| Script | Shows |
|
|
233
|
+
| --- | --- |
|
|
234
|
+
| [`send_message.py`](examples/send_message.py) | Send a message after asking you to confirm it. |
|
|
235
|
+
| [`listen_and_reply.py`](examples/listen_and_reply.py) | Answer messages from a plain asyncio program. |
|
|
236
|
+
| [`agentos_stream.py`](examples/agentos_stream.py) | Answer messages from AgentOS over the event stream. |
|
|
237
|
+
| [`agentos_webhook.py`](examples/agentos_webhook.py) | Answer messages from AgentOS over a signed webhook, replying with `PhotonTools`. |
|
|
238
|
+
|
|
239
|
+
## Development
|
|
240
|
+
|
|
241
|
+
```bash
|
|
242
|
+
uv sync --locked
|
|
243
|
+
uv run ruff format --check
|
|
244
|
+
uv run ruff check
|
|
245
|
+
uv run mypy
|
|
246
|
+
uv run pytest
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
CI runs the same checks, the tests on Python 3.11 to 3.14 and with the lowest allowed dependency versions, and builds the wheel. To release, set the version in `pyproject.toml` and publish a GitHub release tagged `v<version>`; the release workflow builds the package and publishes it to PyPI through trusted publishing.
|
|
250
|
+
|
|
251
|
+
## License
|
|
252
|
+
|
|
253
|
+
Apache-2.0. See [LICENSE](LICENSE).
|