copilotkit 0.1.51__tar.gz → 0.1.51a2__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 (33) hide show
  1. {copilotkit-0.1.51 → copilotkit-0.1.51a2}/PKG-INFO +11 -6
  2. copilotkit-0.1.51a2/copilotkit/__init__.py +57 -0
  3. copilotkit-0.1.51a2/copilotkit/a2ui.py +240 -0
  4. {copilotkit-0.1.51 → copilotkit-0.1.51a2}/copilotkit/action.py +20 -20
  5. {copilotkit-0.1.51 → copilotkit-0.1.51a2}/copilotkit/agent.py +14 -14
  6. copilotkit-0.1.51a2/copilotkit/copilotkit_lg_middleware.py +949 -0
  7. {copilotkit-0.1.51 → copilotkit-0.1.51a2}/copilotkit/crewai/__init__.py +4 -2
  8. {copilotkit-0.1.51 → copilotkit-0.1.51a2}/copilotkit/crewai/copilotkit_integration.py +134 -56
  9. {copilotkit-0.1.51 → copilotkit-0.1.51a2}/copilotkit/crewai/crewai_agent.py +124 -108
  10. {copilotkit-0.1.51 → copilotkit-0.1.51a2}/copilotkit/crewai/crewai_sdk.py +223 -158
  11. {copilotkit-0.1.51 → copilotkit-0.1.51a2}/copilotkit/exc.py +27 -4
  12. copilotkit-0.1.51a2/copilotkit/header_propagation.py +201 -0
  13. {copilotkit-0.1.51 → copilotkit-0.1.51a2}/copilotkit/html.py +3 -1
  14. {copilotkit-0.1.51 → copilotkit-0.1.51a2}/copilotkit/integrations/fastapi.py +80 -74
  15. copilotkit-0.1.51a2/copilotkit/langchain.py +30 -0
  16. {copilotkit-0.1.51 → copilotkit-0.1.51a2}/copilotkit/langgraph.py +166 -163
  17. copilotkit-0.1.51a2/copilotkit/langgraph_agui_agent.py +298 -0
  18. {copilotkit-0.1.51 → copilotkit-0.1.51a2}/copilotkit/logging.py +4 -2
  19. {copilotkit-0.1.51 → copilotkit-0.1.51a2}/copilotkit/parameter.py +23 -15
  20. {copilotkit-0.1.51 → copilotkit-0.1.51a2}/copilotkit/protocol.py +81 -44
  21. copilotkit-0.1.51a2/copilotkit/py.typed +0 -0
  22. {copilotkit-0.1.51 → copilotkit-0.1.51a2}/copilotkit/runloop.py +37 -41
  23. {copilotkit-0.1.51 → copilotkit-0.1.51a2}/copilotkit/sdk.py +31 -35
  24. {copilotkit-0.1.51 → copilotkit-0.1.51a2}/copilotkit/types.py +15 -1
  25. copilotkit-0.1.51a2/copilotkit/utils.py +5 -0
  26. copilotkit-0.1.51a2/pyproject.toml +51 -0
  27. copilotkit-0.1.51/copilotkit/__init__.py +0 -22
  28. copilotkit-0.1.51/copilotkit/langchain.py +0 -31
  29. copilotkit-0.1.51/copilotkit/langgraph_agent.py +0 -647
  30. copilotkit-0.1.51/copilotkit/utils.py +0 -8
  31. copilotkit-0.1.51/pyproject.toml +0 -26
  32. {copilotkit-0.1.51 → copilotkit-0.1.51a2}/README.md +0 -0
  33. {copilotkit-0.1.51 → copilotkit-0.1.51a2}/copilotkit/integrations/__init__.py +0 -0
@@ -1,23 +1,28 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: copilotkit
3
- Version: 0.1.51
3
+ Version: 0.1.51a2
4
4
  Summary: CopilotKit python SDK
5
5
  License: MIT
6
6
  Keywords: copilot,copilotkit,langgraph,langchain,ai,langsmith,langserve
7
7
  Author: Markus Ecker
8
8
  Author-email: markus.ecker@gmail.com
9
- Requires-Python: >=3.10,<3.13
9
+ Requires-Python: >=3.10,<3.15
10
10
  Classifier: License :: OSI Approved :: MIT License
11
11
  Classifier: Programming Language :: Python :: 3
12
12
  Classifier: Programming Language :: Python :: 3.10
13
13
  Classifier: Programming Language :: Python :: 3.11
14
14
  Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Programming Language :: Python :: 3.13
16
+ Classifier: Programming Language :: Python :: 3.14
15
17
  Provides-Extra: crewai
16
- Requires-Dist: crewai (==0.118.0) ; extra == "crewai"
17
- Requires-Dist: fastapi (>=0.115.0,<0.116.0)
18
- Requires-Dist: langchain (==0.3.21)
19
- Requires-Dist: langgraph (==0.3.18)
18
+ Requires-Dist: ag-ui-langgraph[fastapi] (==0.0.42-alpha.0)
19
+ Requires-Dist: ag-ui-protocol (>=0.1.15)
20
+ Requires-Dist: crewai (>=0.118.0) ; (python_version >= "3.10" and python_version < "3.14") and (extra == "crewai")
21
+ Requires-Dist: fastapi (>=0.115.0,<1.0.0)
22
+ Requires-Dist: langchain (>=0.3.0)
23
+ Requires-Dist: langgraph (>=0.3.25,<2)
20
24
  Requires-Dist: partialjson (>=0.0.8,<0.0.9)
25
+ Requires-Dist: pydantic-core (>=2.35.0)
21
26
  Requires-Dist: toml (>=0.10.2,<0.11.0)
22
27
  Project-URL: Homepage, https://copilotkit.ai
23
28
  Project-URL: Repository, https://github.com/CopilotKit/CopilotKit/tree/main/sdk-python
@@ -0,0 +1,57 @@
1
+ """CopilotKit SDK"""
2
+
3
+ from .sdk import (
4
+ CopilotKitRemoteEndpoint,
5
+ CopilotKitContext,
6
+ CopilotKitSDK,
7
+ CopilotKitSDKContext,
8
+ )
9
+ from .action import Action
10
+ from .exc import (
11
+ CopilotKitError,
12
+ CopilotKitMisuseError,
13
+ ActionNotFoundException,
14
+ AgentNotFoundException,
15
+ ActionExecutionException,
16
+ AgentExecutionException,
17
+ )
18
+ from .langgraph import CopilotKitState
19
+ from .parameter import Parameter
20
+ from .agent import Agent
21
+ from .langgraph_agui_agent import LangGraphAGUIAgent
22
+ from .copilotkit_lg_middleware import CopilotKitMiddleware
23
+ from ag_ui_langgraph.middlewares.state_streaming import (
24
+ StateStreamingMiddleware,
25
+ StateItem,
26
+ )
27
+ from .header_propagation import (
28
+ set_forwarded_headers,
29
+ get_forwarded_headers,
30
+ install_httpx_hook,
31
+ )
32
+
33
+
34
+ __all__ = [
35
+ "CopilotKitRemoteEndpoint",
36
+ "CopilotKitSDK",
37
+ "Action",
38
+ "CopilotKitState",
39
+ "Parameter",
40
+ "Agent",
41
+ "CopilotKitContext",
42
+ "CopilotKitSDKContext",
43
+ "CopilotKitError",
44
+ "CopilotKitMisuseError",
45
+ "ActionNotFoundException",
46
+ "AgentNotFoundException",
47
+ "ActionExecutionException",
48
+ "AgentExecutionException",
49
+ "CrewAIAgent", # pyright: ignore[reportUnsupportedDunderAll] pylint: disable=undefined-all-variable
50
+ "LangGraphAGUIAgent",
51
+ "CopilotKitMiddleware",
52
+ "StateStreamingMiddleware",
53
+ "StateItem",
54
+ "set_forwarded_headers",
55
+ "get_forwarded_headers",
56
+ "install_httpx_hook",
57
+ ]
@@ -0,0 +1,240 @@
1
+ """
2
+ A2UI helpers — build v0.9 A2UI operations from schema + data.
3
+
4
+ Usage:
5
+ from copilotkit import a2ui
6
+
7
+ schema = a2ui.load_schema("flight_card.json")
8
+
9
+ @tool
10
+ def search_flights(flights: list[Flight]) -> str:
11
+ return a2ui.render([
12
+ a2ui.create_surface("my-surface"),
13
+ a2ui.update_components("my-surface", schema),
14
+ a2ui.update_data_model("my-surface", {"flights": flights}),
15
+ ])
16
+ """
17
+
18
+ from __future__ import annotations
19
+
20
+ import json
21
+ from pathlib import Path
22
+ from typing import Any
23
+
24
+
25
+ def load_schema(path: str | Path) -> list[dict[str, Any]]:
26
+ """Load an A2UI component schema from a JSON file."""
27
+ with open(path) as f:
28
+ return json.load(f)
29
+
30
+
31
+ def update_components(
32
+ surface_id: str,
33
+ components: list[dict[str, Any]],
34
+ ) -> dict[str, Any]:
35
+ """Build a v0.9 updateComponents operation."""
36
+ return {
37
+ "version": "v0.9",
38
+ "updateComponents": {
39
+ "surfaceId": surface_id,
40
+ "components": components,
41
+ },
42
+ }
43
+
44
+
45
+ def update_data_model(
46
+ surface_id: str,
47
+ data: Any,
48
+ path: str = "/",
49
+ ) -> dict[str, Any]:
50
+ """Build a v0.9 updateDataModel operation with plain JSON value."""
51
+ return {
52
+ "version": "v0.9",
53
+ "updateDataModel": {
54
+ "surfaceId": surface_id,
55
+ "path": path,
56
+ "value": data,
57
+ },
58
+ }
59
+
60
+
61
+ BASIC_CATALOG_ID = "https://a2ui.org/specification/v0_9/basic_catalog.json"
62
+ """The catalog ID for the standard v0.9 basic catalog."""
63
+
64
+
65
+ def create_surface(
66
+ surface_id: str,
67
+ catalog_id: str = BASIC_CATALOG_ID,
68
+ ) -> dict[str, Any]:
69
+ """Build a v0.9 createSurface operation."""
70
+ return {
71
+ "version": "v0.9",
72
+ "createSurface": {
73
+ "surfaceId": surface_id,
74
+ "catalogId": catalog_id,
75
+ },
76
+ }
77
+
78
+
79
+ A2UI_OPERATIONS_KEY = "a2ui_operations"
80
+ """The container key used to wrap A2UI operations for explicit detection."""
81
+
82
+
83
+ def render(operations: list[dict[str, Any]]) -> str:
84
+ """Wrap operations in the a2ui_operations container and serialize to JSON.
85
+
86
+ Args:
87
+ operations: The A2UI v0.9 operations (createSurface, updateComponents, updateDataModel).
88
+
89
+ Example::
90
+ render(
91
+ operations=[...],
92
+ )
93
+ """
94
+ result: dict[str, Any] = {A2UI_OPERATIONS_KEY: operations}
95
+ return json.dumps(result)
96
+
97
+
98
+ # ---------------------------------------------------------------------------
99
+ # Dynamic A2UI prompt builder
100
+ # ---------------------------------------------------------------------------
101
+
102
+ DEFAULT_GENERATION_GUIDELINES = """\
103
+ Generate A2UI v0.9 JSON.
104
+
105
+ ## A2UI Protocol Instructions
106
+
107
+ A2UI (Agent to UI) is a protocol for rendering rich UI surfaces from agent responses.
108
+
109
+ CRITICAL: You MUST call the render_a2ui tool with ALL of these arguments:
110
+ - surfaceId: A unique ID for the surface (e.g. "product-comparison")
111
+ - components: REQUIRED — the A2UI component array. NEVER omit this. Use a List with
112
+ children: { componentId: "card-id", path: "/items" } for repeating cards.
113
+ - data: OPTIONAL — a JSON object written to the root of the surface data model.
114
+ Use for pre-filling form values or providing data for path-bound components.
115
+ - every component must have the "component" field specifying the component type (e.g. "Text", "Image", "Row", "Column", "List", "Button", etc.)
116
+
117
+ COMPONENT ID RULES:
118
+ - Exactly one component MUST have id="root". This is the surface's entry
119
+ point — the renderer begins at "root" and walks the child/children tree
120
+ from there. Every other component must be reachable from "root". If no
121
+ component has id="root", the surface renders an empty loading placeholder
122
+ and none of your components will be shown.
123
+ - Every component ID must be unique within the surface.
124
+ - A component MUST NOT reference itself as child/children. This causes a
125
+ circular dependency error. For example, if a component has id="avatar",
126
+ its child must be a DIFFERENT id (e.g. "avatar-img"), never "avatar".
127
+ - The child/children tree must be a DAG — no cycles allowed.
128
+
129
+ PATH RULES FOR TEMPLATES:
130
+ Components inside a repeating List use RELATIVE paths (no leading slash).
131
+ The path is resolved relative to each array item automatically.
132
+ If List has children: { componentId: "card", path: "/items" } and item has key "name",
133
+ use { "path": "name" } (NO leading slash — relative to item).
134
+ CRITICAL: Do NOT use "/name" (absolute) inside templates — use "name" (relative).
135
+ The List's own path ("/items") uses a leading slash (absolute), but all
136
+ components INSIDE the template card use paths WITHOUT leading slash.
137
+ Do NOT use "/items/0/name" or "/items/{@key}/name" — just "name".
138
+
139
+ COMPONENT VALUES — DEFAULT RULE:
140
+ Use inline literal values for ALL component properties. Pass strings, numbers,
141
+ arrays, and objects directly on the component. Do NOT use { "path": "..." }
142
+ objects unless the property's schema explicitly allows it (see exception below).
143
+ CRITICAL: USING { "path": "..." } ON A PROPERTY THAT DOES NOT DECLARE PATH
144
+ SUPPORT IN ITS SCHEMA WILL CAUSE A RUNTIME CRASH AND BREAK THE ENTIRE UI.
145
+ ALWAYS CHECK THE COMPONENT SCHEMA FIRST — IF THE PROPERTY ONLY ACCEPTS A
146
+ PLAIN TYPE, YOU MUST USE A LITERAL VALUE.
147
+ VERY IMPORTANT: THE APPLICATION WILL BREAK IF YOU DO NOT FOLLOW THIS RULE!
148
+
149
+ For example, a chart's "data" must always be an inline array:
150
+ "data": [{"label": "Jan", "value": 100}, {"label": "Feb", "value": 200}]
151
+ A metric's "value" must always be an inline string:
152
+ "value": "$1,200"
153
+
154
+ PATH BINDING EXCEPTION — SCHEMA-DRIVEN:
155
+ A few properties accept { "path": "/some/path" } as an alternative to a literal
156
+ value. You can identify these in the Available Components schema: the property
157
+ will list BOTH a literal type AND an object-with-path option. If a property only
158
+ shows a single type (string, number, array, etc.), it does NOT support path
159
+ binding — use a literal value only.
160
+
161
+ Path binding is typically used for editable form inputs so the client can write
162
+ user input back to the data model. When building forms:
163
+ - Bind input "value" to a data model path: "value": { "path": "/form/name" }
164
+ - Pre-fill via the "data" tool argument: "data": { "form": { "name": "Alice" } }
165
+ - Capture values on submit via button action context:
166
+ "action": { "event": { "name": "submit", "context": { "name": { "path": "/form/name" } } } }
167
+
168
+ REPEATING CONTENT uses a structural children format (not the same as value binding):
169
+ children: { componentId: "card-id", path: "/items" }
170
+ Components inside templates use RELATIVE paths (no leading slash): { "path": "name" }."""
171
+
172
+ DEFAULT_DESIGN_GUIDELINES = """\
173
+ Create polished, visually appealing interfaces:
174
+ - Always include a title heading (h2) for the surface, outside the List.
175
+ Wrap in a Column: [title, list] as root.
176
+ - For card templates, create clear visual hierarchy:
177
+ - h3 for primary text (names, titles)
178
+ - h2 for featured numbers (prices, scores) — makes them stand out
179
+ - caption for secondary info (ratings, categories, metadata)
180
+ - body for descriptions
181
+ - Use Divider between logical sections within cards.
182
+ - Use Row with justify="spaceBetween" for label-value pairs
183
+ (e.g. "Rating" on left, "4.5/5" on right).
184
+ - Include images when relevant (logos, icons, product photos):
185
+ - Use Image component with variant="smallFeature" or "avatar"
186
+ - Prefer company logos for branded products — Google favicons are reliable:
187
+ https://www.google.com/s2/favicons?domain=sony.com&sz=128
188
+ https://www.google.com/s2/favicons?domain=bose.com&sz=128
189
+ - For generic icons: https://placehold.co/128x128/EEE/999?text=🎧
190
+ - Do NOT invent Unsplash photo-IDs — they will 404. Only use real, known URLs.
191
+ - Use horizontal List direction for side-by-side comparison cards.
192
+ - Keep cards clean — avoid clutter. Whitespace is good.
193
+ - Use consistent surfaceIds (lowercase, hyphenated).
194
+ - NEVER use the same ID for a component and its child — this creates a
195
+ circular dependency. E.g. if id="avatar", child must NOT be "avatar".
196
+ - Both Row and Column support "justify" and "align".
197
+ - Add Button for interactivity. Button needs child (Text ID) + action.
198
+ Action MUST use this exact nested format:
199
+ "action": { "event": { "name": "myAction", "context": { "key": "value" } } }
200
+ The "event" key holds an OBJECT with "name" (required) and "context" (optional).
201
+ Do NOT use a flat format like {"event": "name"} — "event" must be an object.
202
+ Use variant="primary" for main action buttons, variant="borderless" for links.
203
+ - For forms: wrap fields in a Card with a Column. Place the submit button in a
204
+ Row with justify="end". Every input MUST use path binding on the "value" property
205
+ (e.g. "value": { "path": "/form/name" }) to be editable. The submit button's action
206
+ context MUST reference the same paths to capture the user's input.
207
+
208
+ Use the SAME surfaceId as the main surface. Match action names to Button action event names."""
209
+
210
+
211
+ def a2ui_prompt(
212
+ component_schema: str,
213
+ generation_guidelines: str = DEFAULT_GENERATION_GUIDELINES,
214
+ design_guidelines: str = DEFAULT_DESIGN_GUIDELINES,
215
+ ) -> str:
216
+ """Build the system prompt for dynamic A2UI generation.
217
+
218
+ Args:
219
+ component_schema: JSON string of available components and their props.
220
+ Read from state["ag-ui"]["a2ui_schema"].
221
+ generation_guidelines: Instructions for how to call the render_a2ui
222
+ tool, path rules, and data format.
223
+ design_guidelines: Visual design rules, component hierarchy tips,
224
+ and action handler patterns.
225
+
226
+ Returns:
227
+ Complete system prompt string.
228
+ """
229
+ return f"""\
230
+ {generation_guidelines}
231
+
232
+ ## DESIGN GUIDELINES:
233
+ {design_guidelines}
234
+
235
+ ## AVAILABLE COMPONENTS:
236
+ The following components are available for building UI surfaces.
237
+ Use ONLY these components with the specified props.
238
+
239
+ {component_schema}
240
+ """
@@ -5,26 +5,32 @@ from inspect import iscoroutinefunction
5
5
  from typing import Optional, List, Callable, TypedDict, Any, cast
6
6
  from .parameter import Parameter, normalize_parameters
7
7
 
8
+
8
9
  class ActionDict(TypedDict):
9
10
  """Dict representation of an action"""
11
+
10
12
  name: str
11
13
  description: str
12
14
  parameters: List[Parameter]
13
15
 
16
+
14
17
  class ActionResultDict(TypedDict):
15
18
  """Dict representation of an action result"""
19
+
16
20
  result: Any
17
21
 
22
+
18
23
  class Action: # pylint: disable=too-few-public-methods
19
24
  """Action class for CopilotKit"""
25
+
20
26
  def __init__(
21
- self,
22
- *,
23
- name: str,
24
- handler: Callable,
25
- description: Optional[str] = None,
26
- parameters: Optional[List[Parameter]] = None,
27
- ):
27
+ self,
28
+ *,
29
+ name: str,
30
+ handler: Callable,
31
+ description: Optional[str] = None,
32
+ parameters: Optional[List[Parameter]] = None,
33
+ ):
28
34
  self.name = name
29
35
  self.description = description
30
36
  self.parameters = parameters
@@ -32,26 +38,20 @@ class Action: # pylint: disable=too-few-public-methods
32
38
 
33
39
  if not re.match(r"^[a-zA-Z0-9_-]+$", name):
34
40
  raise ValueError(
35
- f"Invalid action name '{name}': " +
36
- "must consist of alphanumeric characters, underscores, and hyphens only"
41
+ f"Invalid action name '{name}': "
42
+ + "must consist of alphanumeric characters, underscores, and hyphens only"
37
43
  )
38
44
 
39
- async def execute(
40
- self,
41
- *,
42
- arguments: dict
43
- ) -> ActionResultDict:
45
+ async def execute(self, *, arguments: dict) -> ActionResultDict:
44
46
  """Execute the action"""
45
47
  result = self.handler(**arguments)
46
48
 
47
- return {
48
- "result": await result if iscoroutinefunction(self.handler) else result
49
- }
49
+ return {"result": await result if iscoroutinefunction(self.handler) else result}
50
50
 
51
51
  def dict_repr(self) -> ActionDict:
52
52
  """Dict representation of the action"""
53
53
  return {
54
- 'name': self.name,
55
- 'description': self.description or '',
56
- 'parameters': normalize_parameters(cast(Any, self.parameters)),
54
+ "name": self.name,
55
+ "description": self.description or "",
56
+ "parameters": normalize_parameters(cast(Any, self.parameters)),
57
57
  }
@@ -7,30 +7,34 @@ from .types import Message
7
7
  from .action import ActionDict
8
8
  from .types import MetaEvent
9
9
 
10
+
10
11
  class AgentDict(TypedDict):
11
12
  """Agent dictionary"""
13
+
12
14
  name: str
13
15
  description: Optional[str]
14
16
 
17
+
15
18
  class Agent(ABC):
16
19
  """Agent class for CopilotKit"""
20
+
17
21
  def __init__(
18
- self,
19
- *,
20
- name: str,
21
- description: Optional[str] = None,
22
- ):
22
+ self,
23
+ *,
24
+ name: str,
25
+ description: Optional[str] = None,
26
+ ):
23
27
  self.name = name
24
28
  self.description = description
25
29
 
26
30
  if not re.match(r"^[a-zA-Z0-9_-]+$", name):
27
31
  raise ValueError(
28
- f"Invalid agent name '{name}': " +
29
- "must consist of alphanumeric characters, underscores, and hyphens only"
32
+ f"Invalid agent name '{name}': "
33
+ + "must consist of alphanumeric characters, underscores, and hyphens only"
30
34
  )
31
35
 
32
36
  @abstractmethod
33
- def execute( # pylint: disable=too-many-arguments
37
+ def execute( # pylint: disable=too-many-arguments
34
38
  self,
35
39
  *,
36
40
  state: dict,
@@ -54,13 +58,9 @@ class Agent(ABC):
54
58
  "threadId": thread_id or "",
55
59
  "threadExists": False,
56
60
  "state": {},
57
- "messages": []
61
+ "messages": [],
58
62
  }
59
63
 
60
-
61
64
  def dict_repr(self) -> AgentDict:
62
65
  """Dict representation of the action"""
63
- return {
64
- 'name': self.name,
65
- 'description': self.description or ''
66
- }
66
+ return {"name": self.name, "description": self.description or ""}