graphcore-apps 0.5.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 (122) hide show
  1. graphcore_apps-0.5.0/LICENSE +202 -0
  2. graphcore_apps-0.5.0/NOTICE +2 -0
  3. graphcore_apps-0.5.0/PKG-INFO +14 -0
  4. graphcore_apps-0.5.0/agents/backend/agents/__init__.py +0 -0
  5. graphcore_apps-0.5.0/agents/backend/agents/apps.py +15 -0
  6. graphcore_apps-0.5.0/agents/backend/agents/authorization.py +62 -0
  7. graphcore_apps-0.5.0/agents/backend/agents/conf.py +78 -0
  8. graphcore_apps-0.5.0/agents/backend/agents/delegation.py +218 -0
  9. graphcore_apps-0.5.0/agents/backend/agents/entities/__init__.py +0 -0
  10. graphcore_apps-0.5.0/agents/backend/agents/entities/agent.py +16 -0
  11. graphcore_apps-0.5.0/agents/backend/agents/entities/conversation.py +23 -0
  12. graphcore_apps-0.5.0/agents/backend/agents/entities/instruction.py +7 -0
  13. graphcore_apps-0.5.0/agents/backend/agents/entities/message.py +30 -0
  14. graphcore_apps-0.5.0/agents/backend/agents/entities/profile.py +14 -0
  15. graphcore_apps-0.5.0/agents/backend/agents/entities/skill.py +8 -0
  16. graphcore_apps-0.5.0/agents/backend/agents/migrations/0001_initial.py +88 -0
  17. graphcore_apps-0.5.0/agents/backend/agents/migrations/0002_message_context_versions.py +16 -0
  18. graphcore_apps-0.5.0/agents/backend/agents/migrations/0003_compaction_threshold.py +21 -0
  19. graphcore_apps-0.5.0/agents/backend/agents/migrations/0004_agent_debug_context.py +16 -0
  20. graphcore_apps-0.5.0/agents/backend/agents/migrations/0005_conversation_last_active_at.py +34 -0
  21. graphcore_apps-0.5.0/agents/backend/agents/migrations/0006_tasks.py +21 -0
  22. graphcore_apps-0.5.0/agents/backend/agents/migrations/0007_agent_start_address.py +16 -0
  23. graphcore_apps-0.5.0/agents/backend/agents/migrations/__init__.py +0 -0
  24. graphcore_apps-0.5.0/agents/backend/agents/models.py +64 -0
  25. graphcore_apps-0.5.0/agents/backend/agents/persistence.py +18 -0
  26. graphcore_apps-0.5.0/agents/backend/agents/providers/__init__.py +0 -0
  27. graphcore_apps-0.5.0/agents/backend/agents/providers/anthropic.py +142 -0
  28. graphcore_apps-0.5.0/agents/backend/agents/providers/fake.py +51 -0
  29. graphcore_apps-0.5.0/agents/backend/agents/providers/google.py +186 -0
  30. graphcore_apps-0.5.0/agents/backend/agents/providers/openai.py +177 -0
  31. graphcore_apps-0.5.0/agents/backend/agents/providers/port.py +101 -0
  32. graphcore_apps-0.5.0/agents/backend/agents/providers/registry.py +40 -0
  33. graphcore_apps-0.5.0/agents/backend/agents/routes.py +5 -0
  34. graphcore_apps-0.5.0/agents/backend/agents/runtime/__init__.py +0 -0
  35. graphcore_apps-0.5.0/agents/backend/agents/runtime/compaction.py +29 -0
  36. graphcore_apps-0.5.0/agents/backend/agents/runtime/context.py +78 -0
  37. graphcore_apps-0.5.0/agents/backend/agents/runtime/dispatch.py +76 -0
  38. graphcore_apps-0.5.0/agents/backend/agents/runtime/effective_agent.py +70 -0
  39. graphcore_apps-0.5.0/agents/backend/agents/runtime/loop.py +454 -0
  40. graphcore_apps-0.5.0/agents/backend/agents/runtime/prompt.py +183 -0
  41. graphcore_apps-0.5.0/agents/backend/agents/runtime/resume.py +30 -0
  42. graphcore_apps-0.5.0/agents/backend/agents/runtime/tools.py +35 -0
  43. graphcore_apps-0.5.0/agents/backend/agents/specs/__init__.py +3 -0
  44. graphcore_apps-0.5.0/agents/backend/agents/specs/dsl.py +310 -0
  45. graphcore_apps-0.5.0/agents/backend/agents/specs/test_r01_agents.py +74 -0
  46. graphcore_apps-0.5.0/agents/backend/agents/specs/test_r02_conversations.py +146 -0
  47. graphcore_apps-0.5.0/agents/backend/agents/specs/test_r03_acts_as_the_sender.py +60 -0
  48. graphcore_apps-0.5.0/agents/backend/agents/specs/test_r04_context.py +63 -0
  49. graphcore_apps-0.5.0/agents/backend/agents/specs/test_r05_personal_configuration.py +86 -0
  50. graphcore_apps-0.5.0/agents/backend/agents/specs/test_r06_delegation.py +70 -0
  51. graphcore_apps-0.5.0/agents/backend/agents/specs/test_r07_sharing.py +103 -0
  52. graphcore_apps-0.5.0/agents/backend/agents/specs/test_r08_embedding.py +40 -0
  53. graphcore_apps-0.5.0/agents/backend/agents/specs/test_r09_finding.py +41 -0
  54. graphcore_apps-0.5.0/agents/backend/agents/specs/test_r10_clients.py +41 -0
  55. graphcore_apps-0.5.0/agents/backend/agents/strategies/__init__.py +0 -0
  56. graphcore_apps-0.5.0/agents/backend/agents/strategies/_schema.py +16 -0
  57. graphcore_apps-0.5.0/agents/backend/agents/strategies/agents.py +93 -0
  58. graphcore_apps-0.5.0/agents/backend/agents/strategies/context.py +45 -0
  59. graphcore_apps-0.5.0/agents/backend/agents/strategies/conversations.py +65 -0
  60. graphcore_apps-0.5.0/agents/backend/agents/strategies/instructions.py +62 -0
  61. graphcore_apps-0.5.0/agents/backend/agents/strategies/messages.py +56 -0
  62. graphcore_apps-0.5.0/agents/backend/agents/strategies/models.py +27 -0
  63. graphcore_apps-0.5.0/agents/backend/agents/strategies/profiles.py +43 -0
  64. graphcore_apps-0.5.0/agents/backend/agents/strategies/skills.py +47 -0
  65. graphcore_apps-0.5.0/agents/backend/agents/strategies/turn.py +47 -0
  66. graphcore_apps-0.5.0/agents/backend/agents/test_settings.py +6 -0
  67. graphcore_apps-0.5.0/agents/backend/agents/tests/__init__.py +0 -0
  68. graphcore_apps-0.5.0/agents/backend/agents/tests/support.py +94 -0
  69. graphcore_apps-0.5.0/agents/backend/agents/tests/test_agent_views.py +181 -0
  70. graphcore_apps-0.5.0/agents/backend/agents/tests/test_agents.py +166 -0
  71. graphcore_apps-0.5.0/agents/backend/agents/tests/test_anthropic_adapter.py +221 -0
  72. graphcore_apps-0.5.0/agents/backend/agents/tests/test_context.py +231 -0
  73. graphcore_apps-0.5.0/agents/backend/agents/tests/test_control.py +162 -0
  74. graphcore_apps-0.5.0/agents/backend/agents/tests/test_conversations.py +158 -0
  75. graphcore_apps-0.5.0/agents/backend/agents/tests/test_delegation.py +392 -0
  76. graphcore_apps-0.5.0/agents/backend/agents/tests/test_google_adapter.py +208 -0
  77. graphcore_apps-0.5.0/agents/backend/agents/tests/test_inspect.py +59 -0
  78. graphcore_apps-0.5.0/agents/backend/agents/tests/test_live_providers.py +69 -0
  79. graphcore_apps-0.5.0/agents/backend/agents/tests/test_openai_adapter.py +259 -0
  80. graphcore_apps-0.5.0/agents/backend/agents/tests/test_profiles.py +92 -0
  81. graphcore_apps-0.5.0/agents/backend/agents/tests/test_resumption.py +150 -0
  82. graphcore_apps-0.5.0/agents/backend/agents/tests/test_turns.py +230 -0
  83. graphcore_apps-0.5.0/agents/backend/agents/validation.py +48 -0
  84. graphcore_apps-0.5.0/agents/backend/agents_agent_frontend/__init__.py +3 -0
  85. graphcore_apps-0.5.0/agents/backend/agents_agent_frontend/agent_views.py +286 -0
  86. graphcore_apps-0.5.0/audio/backend/audio/__init__.py +0 -0
  87. graphcore_apps-0.5.0/audio/backend/audio/apps.py +14 -0
  88. graphcore_apps-0.5.0/audio/backend/audio/authorization.py +13 -0
  89. graphcore_apps-0.5.0/audio/backend/audio/conf.py +27 -0
  90. graphcore_apps-0.5.0/audio/backend/audio/entities/__init__.py +11 -0
  91. graphcore_apps-0.5.0/audio/backend/audio/entities/recording.py +10 -0
  92. graphcore_apps-0.5.0/audio/backend/audio/migrations/0001_initial.py +26 -0
  93. graphcore_apps-0.5.0/audio/backend/audio/migrations/__init__.py +0 -0
  94. graphcore_apps-0.5.0/audio/backend/audio/models.py +9 -0
  95. graphcore_apps-0.5.0/audio/backend/audio/persistence.py +6 -0
  96. graphcore_apps-0.5.0/audio/backend/audio/providers/__init__.py +0 -0
  97. graphcore_apps-0.5.0/audio/backend/audio/providers/fake.py +35 -0
  98. graphcore_apps-0.5.0/audio/backend/audio/providers/openai.py +50 -0
  99. graphcore_apps-0.5.0/audio/backend/audio/providers/port.py +31 -0
  100. graphcore_apps-0.5.0/audio/backend/audio/providers/registry.py +31 -0
  101. graphcore_apps-0.5.0/audio/backend/audio/specs/__init__.py +3 -0
  102. graphcore_apps-0.5.0/audio/backend/audio/specs/dsl.py +120 -0
  103. graphcore_apps-0.5.0/audio/backend/audio/specs/test_clients.py +20 -0
  104. graphcore_apps-0.5.0/audio/backend/audio/specs/test_dictation.py +87 -0
  105. graphcore_apps-0.5.0/audio/backend/audio/specs/test_privacy.py +45 -0
  106. graphcore_apps-0.5.0/audio/backend/audio/specs/test_vendor.py +59 -0
  107. graphcore_apps-0.5.0/audio/backend/audio/strategies/__init__.py +11 -0
  108. graphcore_apps-0.5.0/audio/backend/audio/strategies/recordings.py +88 -0
  109. graphcore_apps-0.5.0/audio/backend/audio/test_settings.py +6 -0
  110. graphcore_apps-0.5.0/audio/backend/audio/tests/__init__.py +0 -0
  111. graphcore_apps-0.5.0/audio/backend/audio/tests/test_openai_adapter.py +65 -0
  112. graphcore_apps-0.5.0/audio/backend/audio/tests/test_recordings.py +139 -0
  113. graphcore_apps-0.5.0/audio/backend/audio_agent_frontend/__init__.py +3 -0
  114. graphcore_apps-0.5.0/audio/backend/audio_agent_frontend/agent_views.py +11 -0
  115. graphcore_apps-0.5.0/graphcore_apps.egg-info/PKG-INFO +14 -0
  116. graphcore_apps-0.5.0/graphcore_apps.egg-info/SOURCES.txt +120 -0
  117. graphcore_apps-0.5.0/graphcore_apps.egg-info/dependency_links.txt +1 -0
  118. graphcore_apps-0.5.0/graphcore_apps.egg-info/entry_points.txt +7 -0
  119. graphcore_apps-0.5.0/graphcore_apps.egg-info/requires.txt +4 -0
  120. graphcore_apps-0.5.0/graphcore_apps.egg-info/top_level.txt +4 -0
  121. graphcore_apps-0.5.0/pyproject.toml +30 -0
  122. graphcore_apps-0.5.0/setup.cfg +4 -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 [yyyy] [name of copyright owner]
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,2 @@
1
+ GraphCore
2
+ Copyright 2026 Andrew Passero
@@ -0,0 +1,14 @@
1
+ Metadata-Version: 2.4
2
+ Name: graphcore-apps
3
+ Version: 0.5.0
4
+ Summary: GraphCore built-in apps
5
+ License-Expression: Apache-2.0
6
+ Project-URL: Repository, https://github.com/graphcore-org/graphcore
7
+ Requires-Python: >=3.13
8
+ License-File: LICENSE
9
+ License-File: NOTICE
10
+ Requires-Dist: graphcore-kernel==0.5.0
11
+ Requires-Dist: anthropic<3,>=2
12
+ Requires-Dist: openai<3,>=2
13
+ Requires-Dist: google-genai<2,>=1
14
+ Dynamic: license-file
File without changes
@@ -0,0 +1,15 @@
1
+ from graphcore.public.apps import GraphCoreAppConfig
2
+
3
+
4
+ class AgentsConfig(GraphCoreAppConfig):
5
+ # Django picks this config for the app package.
6
+ default = True
7
+ name = 'agents'
8
+ # Django app label. Must be unique across the deployment.
9
+ label = 'agents'
10
+ # Stable graphcore identity: namespaces this app's entity type ids and keys
11
+ # its per-user mount folder. Safe to move the package; never change this.
12
+ graphcore_app_id = 'agents'
13
+ graphcore_routes = 'agents.routes.configure'
14
+ graphcore_authorization = 'agents.authorization.configure'
15
+ graphcore_persistence = 'agents.persistence.configure'
@@ -0,0 +1,62 @@
1
+ """Authorization policy for the agents app: the kernel's default roles and
2
+ permissions, with the strategies that need less or more than `Write` listed."""
3
+ from graphcore.public.auth.perms import Create, Delete, Read, Write
4
+ from graphcore.public.auth.policy import AccessPolicy
5
+ from graphcore.public.entities import Deployment
6
+ from graphcore.public.strategies import DeleteEntity
7
+
8
+ from agents.entities.agent import Agent
9
+ from agents.entities.conversation import Conversation
10
+ from agents.entities.instruction import Instruction
11
+ from agents.entities.message import Message
12
+ from agents.entities.profile import AgentProfile
13
+ from agents.entities.skill import Skill
14
+ from agents.strategies.agents import CreateAgent
15
+ from agents.strategies.context import InspectContext
16
+ from agents.strategies.conversations import CreateConversation, UpdateConversation
17
+ from agents.strategies.instructions import CreateInstruction
18
+ from agents.strategies.messages import SendMessage
19
+ from agents.strategies.models import ListModels
20
+ from agents.strategies.profiles import CustomizeAgent
21
+ from agents.strategies.skills import CreateSkill
22
+ from agents.strategies.turn import RunTurn
23
+
24
+
25
+ def configure(policy: AccessPolicy) -> None:
26
+ policy.define(
27
+ Agent, shareable=True, can_contain=[Instruction, Skill],
28
+ strategies={
29
+ CustomizeAgent: Read(),
30
+ CreateConversation: Read(),
31
+ CreateInstruction: Create(),
32
+ CreateSkill: Create(),
33
+ },
34
+ )
35
+ policy.define(Instruction, shareable=True)
36
+ policy.define(Skill, shareable=True)
37
+ policy.define(
38
+ AgentProfile, shareable=False, can_contain=[Instruction, Skill], other_strategies=False,
39
+ strategies={
40
+ CustomizeAgent: Write(),
41
+ CreateInstruction: Create(),
42
+ CreateSkill: Create(),
43
+ DeleteEntity: Delete(),
44
+ },
45
+ )
46
+ policy.define(
47
+ Conversation, shareable=True, can_contain=[Message, Conversation],
48
+ strategies={SendMessage: Write(), RunTurn: Write(), UpdateConversation: Write(), InspectContext: Read()},
49
+ )
50
+ policy.define(
51
+ Message, contained_by=[Conversation], can_contain=[], other_strategies=False,
52
+ strategies={SendMessage: Write(), RunTurn: Write()},
53
+ )
54
+ policy.extend(
55
+ Deployment,
56
+ strategies={
57
+ CreateAgent: Create(),
58
+ CreateInstruction: Create(),
59
+ CreateSkill: Create(),
60
+ ListModels: Read(),
61
+ },
62
+ )
@@ -0,0 +1,78 @@
1
+ """The app's settings, read at call time so a test may override them."""
2
+ import os
3
+ from typing import Optional
4
+
5
+ from django.conf import settings
6
+
7
+ DEFAULT_MODEL = 'anthropic/claude-sonnet-5-5'
8
+ DEFAULT_CONTEXT_SIZE = 200_000
9
+ # The context window each provider's API documents; an entry of AGENTS_MODELS may give its own.
10
+ CONTEXT_SIZES = {
11
+ 'anthropic/claude-sonnet-5-5': 1_000_000,
12
+ 'openai/gpt-5.5': 1_050_000,
13
+ 'google/gemini-3.5-flash': 1_048_576,
14
+ }
15
+ DEFAULT_MAX_OUTPUT_TOKENS = 8192
16
+
17
+
18
+ def default_model() -> str:
19
+ return getattr(settings, 'AGENTS_DEFAULT_MODEL', DEFAULT_MODEL)
20
+
21
+
22
+ def models() -> list[dict]:
23
+ """The catalog, every entry with its `id`, `context_size` and `max_output_tokens`."""
24
+ configured = getattr(settings, 'AGENTS_MODELS', None)
25
+ if configured is None:
26
+ configured = [{'id': default_model()}]
27
+ return [
28
+ {
29
+ 'id': entry['id'],
30
+ 'context_size': entry.get('context_size', CONTEXT_SIZES.get(entry['id'], DEFAULT_CONTEXT_SIZE)),
31
+ 'max_output_tokens': entry.get('max_output_tokens', DEFAULT_MAX_OUTPUT_TOKENS),
32
+ }
33
+ for entry in configured
34
+ ]
35
+
36
+
37
+ def model_entry(model_id: str) -> Optional[dict]:
38
+ return next((entry for entry in models() if entry['id'] == model_id), None)
39
+
40
+
41
+ def provider_key(provider: str) -> Optional[str]:
42
+ name = f'{provider.upper()}_API_KEY'
43
+ return getattr(settings, name, None) or os.environ.get(name) or None
44
+
45
+
46
+ def provider_read_timeout() -> float:
47
+ return float(getattr(settings, 'AGENTS_PROVIDER_READ_TIMEOUT', 60))
48
+
49
+
50
+ def max_steps() -> int:
51
+ return int(getattr(settings, 'AGENTS_MAX_STEPS', 50))
52
+
53
+
54
+ def stream_interval() -> float:
55
+ """Seconds between saves of a streaming assistant message."""
56
+ return float(getattr(settings, 'AGENTS_STREAM_INTERVAL_MS', 500)) / 1000
57
+
58
+
59
+ def lock_poll_seconds() -> float:
60
+ return float(getattr(settings, 'AGENTS_LOCK_POLL_SECONDS', 2))
61
+
62
+
63
+ def compaction_threshold() -> float:
64
+ return float(getattr(settings, 'AGENTS_COMPACTION_THRESHOLD', 0.7))
65
+
66
+
67
+ def max_delegation_depth() -> int:
68
+ return int(getattr(settings, 'AGENTS_MAX_DELEGATION_DEPTH', 1))
69
+
70
+
71
+ def max_attempts() -> int:
72
+ """The kernel's attempt limit for a request (`GRAPHCORE_EXECUTION_MAX_ATTEMPTS`)."""
73
+ return int(getattr(settings, 'GRAPHCORE_EXECUTION_MAX_ATTEMPTS', 6))
74
+
75
+
76
+ def max_tasks() -> int:
77
+ """Background sub-conversations one conversation may have running at once, unless its agent sets its own."""
78
+ return int(getattr(settings, 'AGENTS_MAX_TASKS', 10))
@@ -0,0 +1,218 @@
1
+ """Sub-conversations: a goal handed to an agent in a conversation inside
2
+ the parent's (docs/app_design/agents/AGENTS_TDD.md, Delegation)."""
3
+ import asyncio
4
+ import json
5
+ import time
6
+
7
+ from graphcore.public.entities import Entity
8
+ from graphcore.public.errors import Forbidden, InvalidRequest, NotFound
9
+ from graphcore.public.persistence import AllOf, EntityFilter, Equal
10
+ from graphcore.public.strategies import StrategyRequestPayload, StrategySession
11
+
12
+ from agents import conf
13
+ from agents.entities.agent import Agent
14
+ from agents.entities.conversation import Conversation, ConversationStatus
15
+ from agents.entities.message import Message, MessageRole
16
+ from agents.providers.port import ToolDef
17
+ from agents.runtime.effective_agent import EffectiveAgent
18
+ from agents.runtime.tools import RuntimeTool, ToolFailure
19
+
20
+ _CONVERSATIONS = frozenset({Conversation.get_entity_type_id()})
21
+
22
+ NOTE = (
23
+ "This is a sub-conversation of {parent}. Open it if you need more; its `earlier` tool pages back through "
24
+ "older messages. Your final reply is all that is sent back, so make it a complete report."
25
+ )
26
+
27
+
28
+ def run_turn(conversation: Conversation) -> StrategyRequestPayload:
29
+ """A turn's request. One on a background sub-conversation tells the parent how it ended."""
30
+ callbacks = None
31
+ if conversation.deliver_to_parent and conversation.parent_id:
32
+ callbacks = [StrategyRequestPayload(
33
+ 'SendMessage', {'source_conversation_id': conversation.entity_id}, conversation.parent_id,
34
+ ).to_dict()]
35
+ return StrategyRequestPayload('RunTurn', {}, conversation.entity_id, callbacks=callbacks)
36
+
37
+
38
+ async def stop_waited_children(session: StrategySession, conversation_id: str) -> None:
39
+ """Stops the running sub-conversations a stopped turn waits on. Background
40
+ tasks keep running: each is stopped on its own."""
41
+ cursor = None
42
+ while True:
43
+ page = await session.list(EntityFilter(
44
+ type_ids=_CONVERSATIONS, parent_id=conversation_id,
45
+ where=AllOf((Equal('status', ConversationStatus.RUNNING.value), Equal('deliver_to_parent', False))),
46
+ ), cursor=cursor)
47
+ for child in page.entities:
48
+ child.stop_requested = True
49
+ await session.save(child)
50
+ await stop_waited_children(session, child.entity_id)
51
+ cursor = page.next_cursor
52
+ if cursor is None:
53
+ return
54
+
55
+
56
+ async def _depth(session: StrategySession, conversation: Entity) -> int:
57
+ depth = 0
58
+ while conversation.parent_id:
59
+ conversation = await session.get(conversation.parent_id)
60
+ if not isinstance(conversation, Conversation):
61
+ break
62
+ depth += 1
63
+ return depth
64
+
65
+
66
+ async def _agent(session: StrategySession, named: str) -> Agent:
67
+ try:
68
+ found = await session.get(named)
69
+ except (NotFound, Forbidden, InvalidRequest):
70
+ page = await session.list(EntityFilter(
71
+ type_ids=frozenset({Agent.get_entity_type_id()}), where=AllOf((Equal('key', named),)),
72
+ ), limit=1)
73
+ found = page.entities[0] if page.entities else None
74
+ if not isinstance(found, Agent):
75
+ raise ToolFailure(f"No agent {named!r} that you can read")
76
+ return found
77
+
78
+
79
+ def sub_conversation_tools(session: StrategySession, conversation_id: str) -> list[RuntimeTool]:
80
+ """`delegate`, `start_task` and `stop_task` for one turn. The lock keeps
81
+ the calls of one step from starting more tasks than the limit between
82
+ them; only one turn runs on a conversation at a time."""
83
+ starting = asyncio.Lock()
84
+
85
+ async def start(agent_now: EffectiveAgent, params: dict, call_id: str, agent_id, background: bool):
86
+ goal = params.get('goal')
87
+ if not isinstance(goal, str) or not goal.strip():
88
+ raise ToolFailure("`goal` is required")
89
+ parent = await session.get(conversation_id)
90
+ if await _depth(session, parent) >= conf.max_delegation_depth():
91
+ raise ToolFailure(
92
+ "This conversation is as deep as sub-conversations nest "
93
+ f"(AGENTS_MAX_DELEGATION_DEPTH is {conf.max_delegation_depth()}); do the work here."
94
+ )
95
+ agent_id = agent_id or parent.agent_id
96
+ context_ids = list(params.get('context_ids') or [])
97
+ readable = await session.get_many(context_ids)
98
+ missing = [entity_id for entity_id in context_ids if entity_id not in readable]
99
+ if missing:
100
+ raise ToolFailure(f"Not readable to you: {', '.join(missing)}")
101
+ async with starting:
102
+ if background:
103
+ running = await running_tasks(session, conversation_id)
104
+ if len(running) >= agent_now.max_tasks:
105
+ listed = '\n'.join(f"- {task.entity_id}: {task.title}" for task in running)
106
+ raise ToolFailure(
107
+ f"{len(running)} tasks are running, this agent's limit. Wait for one to report back, "
108
+ f"or stop one with `stop_task`:\n{listed}"
109
+ )
110
+ child = await session.save(session.create(
111
+ Conversation, parent_id=conversation_id, agent_id=agent_id, title=goal[:80],
112
+ context_ids=context_ids, deliver_to_parent=background, source_call_id=call_id,
113
+ status=ConversationStatus.RUNNING, last_active_at=time.time(),
114
+ ))
115
+ await session.save(session.create(
116
+ Message, parent_id=child.entity_id, role=MessageRole.SYSTEM, content=NOTE.format(parent=conversation_id),
117
+ ))
118
+ await session.save(session.create(
119
+ Message, parent_id=child.entity_id, role=MessageRole.USER, content=goal,
120
+ ))
121
+ request, _ = await session.execute(run_turn(child), wait=not background)
122
+ return child, request
123
+
124
+ async def delegate(agent_now: EffectiveAgent, params: dict, call_id: str) -> str:
125
+ agent = await _agent(session, str(params.get('agent')))
126
+ background = bool(params.get('background'))
127
+ child, request = await start(agent_now, params, call_id, agent.entity_id, background)
128
+ if background:
129
+ return json.dumps({'conversation_id': child.entity_id})
130
+ if request.status != 'succeeded':
131
+ raise ToolFailure(
132
+ f"The sub-conversation {child.entity_id} did not finish: {request.error or request.status}"
133
+ )
134
+ return json.dumps({
135
+ 'conversation_id': child.entity_id,
136
+ 'status': request.ret_val.get('status'), 'text': request.ret_val.get('text'),
137
+ **({'cut_off': True} if request.ret_val.get('cut_off') else {}),
138
+ })
139
+
140
+ async def start_task(agent_now: EffectiveAgent, params: dict, call_id: str) -> str:
141
+ child, _ = await start(agent_now, params, call_id, None, background=True)
142
+ return json.dumps({'conversation_id': child.entity_id})
143
+
144
+ async def stop_task(_agent_now: EffectiveAgent, params: dict, _call_id: str) -> str:
145
+ task_id = str(params.get('task'))
146
+ try:
147
+ task = await session.get(task_id)
148
+ except (NotFound, Forbidden, InvalidRequest):
149
+ task = None
150
+ if not isinstance(task, Conversation) or task.parent_id != conversation_id:
151
+ raise ToolFailure(f"{task_id} is not a sub-conversation of this conversation")
152
+ if task.status is not ConversationStatus.RUNNING:
153
+ return f"{task_id} is not running."
154
+ await session.execute(StrategyRequestPayload('UpdateConversation', {'stop': True}, task_id))
155
+ return f"Stopping {task_id}." + (" It reports back once it has stopped." if task.deliver_to_parent else "")
156
+
157
+ ids = {"type": "array", "items": {"type": "string"}, "description": "Entities rendered for it on its first turn"}
158
+ goal = {"type": "string", "description": "Its first message. It does not see this conversation's messages, so say everything it needs"}
159
+ return [
160
+ RuntimeTool(
161
+ ToolDef(
162
+ 'delegate',
163
+ "Hand a goal to another agent in a sub-conversation of this one. By default you wait, and get how its "
164
+ "turn ended and its final reply as `text`. To do several things at once, call `delegate` several "
165
+ "times in the same step: they run in parallel and you get every result together. Use `background` "
166
+ "for long work the person is not waiting on, or when they want to keep talking meanwhile: you get the "
167
+ "sub-conversation's id now and its final reply later as a message. To work on something yourself in "
168
+ "the background, use `start_task`.",
169
+ {
170
+ "type": "object",
171
+ "properties": {
172
+ "agent": {"type": "string", "description": "The agent's key or id"},
173
+ "goal": goal,
174
+ "context_ids": ids,
175
+ "background": {"type": "boolean"},
176
+ },
177
+ "required": ["agent", "goal"],
178
+ },
179
+ ),
180
+ delegate,
181
+ ),
182
+ RuntimeTool(
183
+ ToolDef(
184
+ 'start_task',
185
+ "Work on a goal yourself in the background, in a task (a sub-conversation of this one), so you and "
186
+ "the person can keep talking meanwhile. You get the task's id now. Its final reply arrives later as a "
187
+ "message, and you take a turn to act on it. Start several to do several things at once. A task keeps "
188
+ "running if this conversation is stopped; `stop_task` stops it.",
189
+ {
190
+ "type": "object",
191
+ "properties": {"goal": goal, "context_ids": ids},
192
+ "required": ["goal"],
193
+ },
194
+ ),
195
+ start_task,
196
+ ),
197
+ RuntimeTool(
198
+ ToolDef(
199
+ 'stop_task',
200
+ "Stop a running task, or a sub-conversation of this one. It reports back its text so far and the tool "
201
+ "calls it made. Tasks it started itself keep running.",
202
+ {
203
+ "type": "object",
204
+ "properties": {"task": {"type": "string", "description": "The id `start_task` or `delegate` returned"}},
205
+ "required": ["task"],
206
+ },
207
+ ),
208
+ stop_task,
209
+ ),
210
+ ]
211
+
212
+
213
+ async def running_tasks(session: StrategySession, conversation_id: str) -> list[Conversation]:
214
+ """The background sub-conversations of a conversation that are running."""
215
+ return await session.list_all(EntityFilter(
216
+ type_ids=_CONVERSATIONS, parent_id=conversation_id,
217
+ where=AllOf((Equal('status', ConversationStatus.RUNNING.value), Equal('deliver_to_parent', True))),
218
+ ))
@@ -0,0 +1,16 @@
1
+ from typing import Optional
2
+
3
+ from graphcore.public.entities import Entity, register_entity
4
+
5
+
6
+ @register_entity()
7
+ class Agent(Entity):
8
+ name: str = ''
9
+ description: str = ''
10
+ instruction_ids: list[str] = []
11
+ skill_ids: list[str] = []
12
+ model: Optional[str] = None
13
+ compaction_threshold: Optional[float] = None
14
+ debug_context: bool = False
15
+ max_tasks: Optional[int] = None
16
+ start_address: Optional[str] = None
@@ -0,0 +1,23 @@
1
+ from enum import StrEnum
2
+ from typing import Optional
3
+
4
+ from graphcore.public.entities import Entity, register_entity
5
+
6
+
7
+ class ConversationStatus(StrEnum):
8
+ IDLE = 'idle'
9
+ RUNNING = 'running'
10
+
11
+
12
+ @register_entity()
13
+ class Conversation(Entity):
14
+ agent_id: Optional[str] = None
15
+ title: str = ''
16
+ status: ConversationStatus = ConversationStatus.IDLE
17
+ context_ids: list[str] = []
18
+ model: Optional[str] = None
19
+ usage: dict = {}
20
+ stop_requested: bool = False
21
+ deliver_to_parent: bool = False
22
+ last_active_at: Optional[float] = None
23
+ source_call_id: Optional[str] = None
@@ -0,0 +1,7 @@
1
+ from graphcore.public.entities import Entity, register_entity
2
+
3
+
4
+ @register_entity()
5
+ class Instruction(Entity):
6
+ name: str = ''
7
+ text: str = ''