agentkernel 0.1.0a2__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 (36) hide show
  1. agentkernel-0.1.0a2/PKG-INFO +250 -0
  2. agentkernel-0.1.0a2/README.md +207 -0
  3. agentkernel-0.1.0a2/pyproject.toml +95 -0
  4. agentkernel-0.1.0a2/src/agentkernel/__init__.py +21 -0
  5. agentkernel-0.1.0a2/src/agentkernel/a2a/__init__.py +0 -0
  6. agentkernel-0.1.0a2/src/agentkernel/a2a/a2a.py +108 -0
  7. agentkernel-0.1.0a2/src/agentkernel/adk/__init__.py +16 -0
  8. agentkernel-0.1.0a2/src/agentkernel/adk/adk.py +165 -0
  9. agentkernel-0.1.0a2/src/agentkernel/api/__init__.py +13 -0
  10. agentkernel-0.1.0a2/src/agentkernel/api/a2a.py +78 -0
  11. agentkernel-0.1.0a2/src/agentkernel/api/agent.py +87 -0
  12. agentkernel-0.1.0a2/src/agentkernel/api/restapi.py +78 -0
  13. agentkernel-0.1.0a2/src/agentkernel/aws/__init__.py +14 -0
  14. agentkernel-0.1.0a2/src/agentkernel/aws/aklambda.py +74 -0
  15. agentkernel-0.1.0a2/src/agentkernel/cli/__init__.py +14 -0
  16. agentkernel-0.1.0a2/src/agentkernel/cli/cli.py +103 -0
  17. agentkernel-0.1.0a2/src/agentkernel/core/__init__.py +18 -0
  18. agentkernel-0.1.0a2/src/agentkernel/core/base.py +169 -0
  19. agentkernel-0.1.0a2/src/agentkernel/core/config.py +170 -0
  20. agentkernel-0.1.0a2/src/agentkernel/core/module.py +28 -0
  21. agentkernel-0.1.0a2/src/agentkernel/core/runtime.py +99 -0
  22. agentkernel-0.1.0a2/src/agentkernel/core/service.py +125 -0
  23. agentkernel-0.1.0a2/src/agentkernel/core/sessions/__init__.py +15 -0
  24. agentkernel-0.1.0a2/src/agentkernel/core/sessions/base.py +45 -0
  25. agentkernel-0.1.0a2/src/agentkernel/core/sessions/in_memory.py +61 -0
  26. agentkernel-0.1.0a2/src/agentkernel/core/sessions/redis.py +242 -0
  27. agentkernel-0.1.0a2/src/agentkernel/crewai/__init__.py +16 -0
  28. agentkernel-0.1.0a2/src/agentkernel/crewai/crewai.py +176 -0
  29. agentkernel-0.1.0a2/src/agentkernel/langgraph/__init__.py +16 -0
  30. agentkernel-0.1.0a2/src/agentkernel/langgraph/langgraph.py +176 -0
  31. agentkernel-0.1.0a2/src/agentkernel/mcp/__init__.py +13 -0
  32. agentkernel-0.1.0a2/src/agentkernel/mcp/akmcp.py +74 -0
  33. agentkernel-0.1.0a2/src/agentkernel/openai/__init__.py +16 -0
  34. agentkernel-0.1.0a2/src/agentkernel/openai/openai.py +148 -0
  35. agentkernel-0.1.0a2/src/agentkernel/test/__init__.py +8 -0
  36. agentkernel-0.1.0a2/src/agentkernel/test/test.py +125 -0
@@ -0,0 +1,250 @@
1
+ Metadata-Version: 2.3
2
+ Name: agentkernel
3
+ Version: 0.1.0a2
4
+ Summary: Agent Kernel Python Distribution
5
+ Author: Yaala Labs
6
+ Author-email: Yaala Labs <info@yaalalabs.com>
7
+ License: MIT
8
+ Requires-Dist: pydantic>=2.11.7
9
+ Requires-Dist: pydantic-settings>=2.10.1
10
+ Requires-Dist: pyyaml>=6.0.2
11
+ Requires-Dist: redis>=6.4.0
12
+ Requires-Dist: a2a-sdk[http-server]>=0.3.6 ; extra == 'a2a'
13
+ Requires-Dist: google-adk>=1.14.1 ; extra == 'adk'
14
+ Requires-Dist: litellm~=1.74.3 ; extra == 'adk'
15
+ Requires-Dist: fastapi>=0.118.0 ; extra == 'api'
16
+ Requires-Dist: uvicorn>=0.37.0 ; extra == 'api'
17
+ Requires-Dist: gunicorn>=23.0.0 ; extra == 'api'
18
+ Requires-Dist: crewai>=0.150.0 ; extra == 'crewai'
19
+ Requires-Dist: langgraph~=0.6.2 ; extra == 'langgraph'
20
+ Requires-Dist: langchain~=0.3.27 ; extra == 'langgraph'
21
+ Requires-Dist: langchain-community~=0.3.27 ; extra == 'langgraph'
22
+ Requires-Dist: litellm~=1.74.3 ; extra == 'langgraph'
23
+ Requires-Dist: fastmcp>=2.12.4 ; extra == 'mcp'
24
+ Requires-Dist: openai-agents>=0.2.3 ; extra == 'openai'
25
+ Requires-Dist: pytest>=8.4.1 ; extra == 'test'
26
+ Requires-Dist: pytest-asyncio>=1.2.0 ; extra == 'test'
27
+ Requires-Dist: pytest-cov>=6.2.1 ; extra == 'test'
28
+ Requires-Dist: pytest-html>=4.1.1 ; extra == 'test'
29
+ Requires-Dist: pytest-order>=1.3.0 ; extra == 'test'
30
+ Requires-Dist: rapidfuzz>=3.14.1 ; extra == 'test'
31
+ Requires-Python: >=3.12
32
+ Provides-Extra: a2a
33
+ Provides-Extra: adk
34
+ Provides-Extra: api
35
+ Provides-Extra: aws
36
+ Provides-Extra: cli
37
+ Provides-Extra: crewai
38
+ Provides-Extra: langgraph
39
+ Provides-Extra: mcp
40
+ Provides-Extra: openai
41
+ Provides-Extra: test
42
+ Description-Content-Type: text/markdown
43
+
44
+ # Agent Kernel (Python)
45
+
46
+ Agent Kernel is a lightweight runtime and adapter layer that lets you build and run AI agents across multiple frameworks with a unified API. This package brings a common set of abstractions (Agent, Runner, Session, Module, Runtime) and integrations for:
47
+
48
+ - OpenAI Agents SDK
49
+ - CrewAI
50
+ - LangGraph
51
+
52
+ It also provides a simple interactive CLI and an AWS Lambda handler to deploy your agents as serverless endpoints.
53
+
54
+
55
+ ## Why Agent Kernel?
56
+
57
+ - Unified model: Write agent logic once, run it under different frameworks via thin adapters.
58
+ - Pluggable: Bring your own framework-specific agents and register them using a small shim.
59
+ - Session-aware: Built-in session abstraction to maintain conversational or task state across runs.
60
+ - Ready to use: CLI for local interaction, AWS Lambda handler for quick cloud deployment.
61
+
62
+
63
+ ## Installation
64
+
65
+ This repository uses the uv toolchain. You can work from source easily.
66
+
67
+ Prerequisites:
68
+ - Python 3.12+
69
+ - uv 0.8.0+
70
+
71
+ From source (editable):
72
+
73
+ ```bash
74
+ # Clone the repo and cd into ak-py
75
+ uv sync # install dependencies
76
+ ```
77
+
78
+ Or using pip (if you package/publish it):
79
+
80
+ ```bash
81
+ pip install ak-py
82
+ ```
83
+
84
+
85
+ ## Quick Start
86
+
87
+ Below is the minimal mental model:
88
+
89
+ - Agent: your framework-specific agent (e.g., a CrewAI Agent or a LangGraph CompiledStateGraph) wrapped by an Agent Kernel adapter.
90
+ - Runner: framework-specific execution strategy.
91
+ - Session: shared state across turns.
92
+ - Module: a container that registers agents with the global Runtime on import/instantiation.
93
+ - Runtime: a registry and orchestrator for agents.
94
+
95
+ ### Example: Define and register agents
96
+
97
+ You typically create a Python module that constructs your framework agents and registers them with Agent Kernel by creating an agent module. Importing this module will register agents in the Runtime.
98
+
99
+ CrewAI example (pseudo/minimal):
100
+
101
+ ```python
102
+ # demo.py
103
+ from crewai import Agent as CrewAgent
104
+ from agentkernel.cli import CLI
105
+ from agentkernel.crewai import CrewAIModule
106
+
107
+ researcher = CrewAgent(role="researcher", goal="Find facts")
108
+ writer = CrewAgent(role="writer", goal="Summarize findings")
109
+
110
+ # Register both under Agent Kernel. The module maps each Crew agent to a CrewAIAgent
111
+ # and registers them with the global Runtime.
112
+ module = CrewAIModule([researcher, writer])
113
+ if __name__ == "__main__":
114
+ CLI.main()
115
+ ```
116
+
117
+ LangGraph example (pseudo/minimal):
118
+
119
+ ```python
120
+ # demo.py
121
+ from langgraph.graph import StateGraph
122
+ from agentkernel.cli import CLI
123
+ from agentkernel.langgraph import LangGraphModule
124
+
125
+ # Build your graph and compile it to CompiledStateGraph with a `.name`
126
+ sg = StateGraph(...)
127
+ compiled = sg.compile()
128
+ compiled.name = "assistant" # ensure a name is set
129
+
130
+ module = LangGraphModule([compiled])
131
+ if __name__ == "__main__":
132
+ CLI.main()
133
+ ```
134
+
135
+ OpenAI Agents SDK example (pseudo/minimal):
136
+
137
+ ```python
138
+ # demo.py
139
+ from openai import OpenAI
140
+ from agents import Agent as OpenAIAgent # from openai-agents SDK
141
+ from agentkernel.cli import CLI
142
+ from agentkernel.openai import OpenAIModule
143
+
144
+ client = OpenAI()
145
+ assistant = OpenAIAgent(name="assistant", client=client) # add any required params for your SDK version
146
+
147
+ module = OpenAIModule([assistant])
148
+ if __name__ == "__main__":
149
+ CLI.main()
150
+ ```
151
+
152
+
153
+ ## Using the CLI
154
+
155
+ Agent Kernel ships with a simple interactive CLI that lets you:
156
+ - Load an agent module (which registers agents)
157
+ - List/select an agent
158
+ - Send prompts and view responses
159
+
160
+ Run one of the above examples from the project:
161
+
162
+ ```bash
163
+ uv run demo.py
164
+ ```
165
+
166
+ Once inside, available commands:
167
+ - !h, !help — Show help
168
+ - !ld, !load <module_name> — Import a Python module that instantiates an agent module (e.g., my_crewai_agents)
169
+ - !ls, !list — List registered agents
170
+ - !s, !select <agent_name> — Select an agent by name
171
+ - !n, !new — Start a new session
172
+ - !q, !quit — Exit
173
+
174
+ Tip: If your agent module registers at import time, you can simply run:
175
+
176
+ ```text
177
+ (assistant) >> !load my_crewai_agents
178
+ ```
179
+
180
+
181
+ ## AWS Lambda Deployment
182
+
183
+ A ready-to-use handler is provided at:
184
+
185
+ - ak.aws:Lambda.handler
186
+
187
+ OpenAI Agents SDK lambda example (pseudo/minimal):
188
+
189
+ ```python
190
+ # demo.py
191
+ from openai import OpenAI
192
+ from agents import Agent as OpenAIAgent # from openai-agents SDK
193
+ from agentkernel.aws import Lambda
194
+ from agentkernel.openai import OpenAIModule
195
+
196
+ client = OpenAI()
197
+ assistant = OpenAIAgent(name="assistant", client=client) # add any required params for your SDK version
198
+
199
+ module = OpenAIModule([assistant])
200
+ handler = Lambda.handler
201
+ ```
202
+
203
+ It expects an API Gateway-style event with a JSON body like:
204
+
205
+ ```json
206
+ {
207
+ "prompt": "Hello agent",
208
+ "agent": "writer"
209
+ }
210
+ ```
211
+
212
+ Response shape:
213
+ - 200 with { "result": <string> }
214
+ - 400 if no agent is available
215
+ - 500 on unexpected errors
216
+
217
+ Notes:
218
+ - If no agent name is provided, the handler selects the first registered agent.
219
+ - Make sure your deployment package (Lambda layer or container) includes your agent module and dependencies. Importing your agent module should register agents before the first request.
220
+
221
+ ## Development
222
+
223
+ Requirements:
224
+ - Python 3.12+
225
+ - uv 0.8.0+
226
+
227
+ Setup:
228
+
229
+ ```bash
230
+ ./build.sh # installs dev dependencies and sets up environment
231
+ ```
232
+
233
+ Run tests:
234
+
235
+ ```bash
236
+ uv run pytest
237
+ ```
238
+
239
+ Formatting and static checks (configured in pyproject.toml):
240
+ - black
241
+ - isort
242
+ - mypy
243
+
244
+
245
+ ## Configuration and Extensibility
246
+
247
+ - Configuration: See [CONFIG.md](CONFIG.md) for full details on environment variables and config file options.
248
+ - Sessions: Use ak.ak.Session to keep per-conversation or per-job state across runs. Framework adapters manage their own session storage within that Session via namespaced keys (e.g., "crewai", "langgraph", "openai").
249
+ - Adapters: See ak/crewai, ak/langgraph, ak/openai for reference implementations. To add a new framework, implement a Runner and an Agent wrapper, then a Module that registers them with Runtime.
250
+ - Runtime: Agents are registered globally; Runtime.load(module_name) imports a module, which should instantiate an agent module to register its agents.
@@ -0,0 +1,207 @@
1
+ # Agent Kernel (Python)
2
+
3
+ Agent Kernel is a lightweight runtime and adapter layer that lets you build and run AI agents across multiple frameworks with a unified API. This package brings a common set of abstractions (Agent, Runner, Session, Module, Runtime) and integrations for:
4
+
5
+ - OpenAI Agents SDK
6
+ - CrewAI
7
+ - LangGraph
8
+
9
+ It also provides a simple interactive CLI and an AWS Lambda handler to deploy your agents as serverless endpoints.
10
+
11
+
12
+ ## Why Agent Kernel?
13
+
14
+ - Unified model: Write agent logic once, run it under different frameworks via thin adapters.
15
+ - Pluggable: Bring your own framework-specific agents and register them using a small shim.
16
+ - Session-aware: Built-in session abstraction to maintain conversational or task state across runs.
17
+ - Ready to use: CLI for local interaction, AWS Lambda handler for quick cloud deployment.
18
+
19
+
20
+ ## Installation
21
+
22
+ This repository uses the uv toolchain. You can work from source easily.
23
+
24
+ Prerequisites:
25
+ - Python 3.12+
26
+ - uv 0.8.0+
27
+
28
+ From source (editable):
29
+
30
+ ```bash
31
+ # Clone the repo and cd into ak-py
32
+ uv sync # install dependencies
33
+ ```
34
+
35
+ Or using pip (if you package/publish it):
36
+
37
+ ```bash
38
+ pip install ak-py
39
+ ```
40
+
41
+
42
+ ## Quick Start
43
+
44
+ Below is the minimal mental model:
45
+
46
+ - Agent: your framework-specific agent (e.g., a CrewAI Agent or a LangGraph CompiledStateGraph) wrapped by an Agent Kernel adapter.
47
+ - Runner: framework-specific execution strategy.
48
+ - Session: shared state across turns.
49
+ - Module: a container that registers agents with the global Runtime on import/instantiation.
50
+ - Runtime: a registry and orchestrator for agents.
51
+
52
+ ### Example: Define and register agents
53
+
54
+ You typically create a Python module that constructs your framework agents and registers them with Agent Kernel by creating an agent module. Importing this module will register agents in the Runtime.
55
+
56
+ CrewAI example (pseudo/minimal):
57
+
58
+ ```python
59
+ # demo.py
60
+ from crewai import Agent as CrewAgent
61
+ from agentkernel.cli import CLI
62
+ from agentkernel.crewai import CrewAIModule
63
+
64
+ researcher = CrewAgent(role="researcher", goal="Find facts")
65
+ writer = CrewAgent(role="writer", goal="Summarize findings")
66
+
67
+ # Register both under Agent Kernel. The module maps each Crew agent to a CrewAIAgent
68
+ # and registers them with the global Runtime.
69
+ module = CrewAIModule([researcher, writer])
70
+ if __name__ == "__main__":
71
+ CLI.main()
72
+ ```
73
+
74
+ LangGraph example (pseudo/minimal):
75
+
76
+ ```python
77
+ # demo.py
78
+ from langgraph.graph import StateGraph
79
+ from agentkernel.cli import CLI
80
+ from agentkernel.langgraph import LangGraphModule
81
+
82
+ # Build your graph and compile it to CompiledStateGraph with a `.name`
83
+ sg = StateGraph(...)
84
+ compiled = sg.compile()
85
+ compiled.name = "assistant" # ensure a name is set
86
+
87
+ module = LangGraphModule([compiled])
88
+ if __name__ == "__main__":
89
+ CLI.main()
90
+ ```
91
+
92
+ OpenAI Agents SDK example (pseudo/minimal):
93
+
94
+ ```python
95
+ # demo.py
96
+ from openai import OpenAI
97
+ from agents import Agent as OpenAIAgent # from openai-agents SDK
98
+ from agentkernel.cli import CLI
99
+ from agentkernel.openai import OpenAIModule
100
+
101
+ client = OpenAI()
102
+ assistant = OpenAIAgent(name="assistant", client=client) # add any required params for your SDK version
103
+
104
+ module = OpenAIModule([assistant])
105
+ if __name__ == "__main__":
106
+ CLI.main()
107
+ ```
108
+
109
+
110
+ ## Using the CLI
111
+
112
+ Agent Kernel ships with a simple interactive CLI that lets you:
113
+ - Load an agent module (which registers agents)
114
+ - List/select an agent
115
+ - Send prompts and view responses
116
+
117
+ Run one of the above examples from the project:
118
+
119
+ ```bash
120
+ uv run demo.py
121
+ ```
122
+
123
+ Once inside, available commands:
124
+ - !h, !help — Show help
125
+ - !ld, !load <module_name> — Import a Python module that instantiates an agent module (e.g., my_crewai_agents)
126
+ - !ls, !list — List registered agents
127
+ - !s, !select <agent_name> — Select an agent by name
128
+ - !n, !new — Start a new session
129
+ - !q, !quit — Exit
130
+
131
+ Tip: If your agent module registers at import time, you can simply run:
132
+
133
+ ```text
134
+ (assistant) >> !load my_crewai_agents
135
+ ```
136
+
137
+
138
+ ## AWS Lambda Deployment
139
+
140
+ A ready-to-use handler is provided at:
141
+
142
+ - ak.aws:Lambda.handler
143
+
144
+ OpenAI Agents SDK lambda example (pseudo/minimal):
145
+
146
+ ```python
147
+ # demo.py
148
+ from openai import OpenAI
149
+ from agents import Agent as OpenAIAgent # from openai-agents SDK
150
+ from agentkernel.aws import Lambda
151
+ from agentkernel.openai import OpenAIModule
152
+
153
+ client = OpenAI()
154
+ assistant = OpenAIAgent(name="assistant", client=client) # add any required params for your SDK version
155
+
156
+ module = OpenAIModule([assistant])
157
+ handler = Lambda.handler
158
+ ```
159
+
160
+ It expects an API Gateway-style event with a JSON body like:
161
+
162
+ ```json
163
+ {
164
+ "prompt": "Hello agent",
165
+ "agent": "writer"
166
+ }
167
+ ```
168
+
169
+ Response shape:
170
+ - 200 with { "result": <string> }
171
+ - 400 if no agent is available
172
+ - 500 on unexpected errors
173
+
174
+ Notes:
175
+ - If no agent name is provided, the handler selects the first registered agent.
176
+ - Make sure your deployment package (Lambda layer or container) includes your agent module and dependencies. Importing your agent module should register agents before the first request.
177
+
178
+ ## Development
179
+
180
+ Requirements:
181
+ - Python 3.12+
182
+ - uv 0.8.0+
183
+
184
+ Setup:
185
+
186
+ ```bash
187
+ ./build.sh # installs dev dependencies and sets up environment
188
+ ```
189
+
190
+ Run tests:
191
+
192
+ ```bash
193
+ uv run pytest
194
+ ```
195
+
196
+ Formatting and static checks (configured in pyproject.toml):
197
+ - black
198
+ - isort
199
+ - mypy
200
+
201
+
202
+ ## Configuration and Extensibility
203
+
204
+ - Configuration: See [CONFIG.md](CONFIG.md) for full details on environment variables and config file options.
205
+ - Sessions: Use ak.ak.Session to keep per-conversation or per-job state across runs. Framework adapters manage their own session storage within that Session via namespaced keys (e.g., "crewai", "langgraph", "openai").
206
+ - Adapters: See ak/crewai, ak/langgraph, ak/openai for reference implementations. To add a new framework, implement a Runner and an Agent wrapper, then a Module that registers them with Runtime.
207
+ - Runtime: Agents are registered globally; Runtime.load(module_name) imports a module, which should instantiate an agent module to register its agents.
@@ -0,0 +1,95 @@
1
+ [build-system]
2
+ requires = ["uv_build>=0.8.2,<0.9.0"]
3
+ build-backend = "uv_build"
4
+
5
+ [project]
6
+ name = "agentkernel"
7
+ version = "0.1.0a2"
8
+ description = "Agent Kernel Python Distribution"
9
+ readme = "README.md"
10
+ requires-python = ">=3.12"
11
+ license = { text = "MIT" }
12
+ authors = [
13
+ { name = "Yaala Labs", email = "info@yaalalabs.com" }
14
+ ]
15
+ dependencies = [
16
+ "pydantic>=2.11.7",
17
+ "pydantic-settings>=2.10.1",
18
+ "pyyaml>=6.0.2",
19
+ "redis>=6.4.0",
20
+ ]
21
+
22
+ [project.optional-dependencies]
23
+ crewai = [
24
+ "crewai>=0.150.0"
25
+ ]
26
+ langgraph = [
27
+ "langgraph~=0.6.2",
28
+ "langchain~=0.3.27",
29
+ "langchain_community~=0.3.27",
30
+ "litellm~=1.74.3"
31
+ ]
32
+ cli = [
33
+
34
+ ]
35
+ aws = [
36
+
37
+ ]
38
+ openai = [
39
+ "openai-agents>=0.2.3"
40
+ ]
41
+ adk = [
42
+ "google-adk>=1.14.1",
43
+ "litellm~=1.74.3"
44
+ ]
45
+ api = [
46
+ "fastapi>=0.118.0",
47
+ "uvicorn>=0.37.0",
48
+ "gunicorn>=23.0.0"
49
+ ]
50
+ test = [
51
+ "pytest>=8.4.1",
52
+ "pytest-asyncio>=1.2.0",
53
+ "pytest-cov>=6.2.1",
54
+ "pytest-html>=4.1.1",
55
+ "pytest-order>=1.3.0",
56
+ "rapidfuzz>=3.14.1",
57
+ ]
58
+ a2a = [
59
+ "a2a-sdk[http-server]>=0.3.6",
60
+ ]
61
+ mcp = [
62
+ "fastmcp>=2.12.4",
63
+ ]
64
+
65
+ [dependency-groups]
66
+ dev = [
67
+ "black>=23.0.0",
68
+ "isort>=5.0.0",
69
+ "mypy>=1.0.0",
70
+ ]
71
+
72
+
73
+ [tool.uv]
74
+ package = true
75
+
76
+ [tool.isort]
77
+ profile = "black"
78
+ line_length = 88
79
+
80
+ [tool.mypy]
81
+ python_version = "3.12"
82
+
83
+ # Common tool configurations that apply to all packages
84
+ [tool.black]
85
+ line-length = 88
86
+ target-version = ["py312"]
87
+
88
+ warn_return_any = true
89
+ warn_unused_configs = true
90
+ disallow_untyped_defs = true
91
+ disallow_incomplete_defs = true
92
+
93
+ [tool.pytest.ini_options]
94
+ addopts = "--cov=src --cov-report=term --cov-report=html --html=report.html"
95
+
@@ -0,0 +1,21 @@
1
+ """
2
+ Agent Kernel Python Distribution.
3
+
4
+ This package provides a unified framework for working with different agent implementations and SDKs.
5
+ It includes core functionality for agent execution, modular integration, and runtime management.
6
+
7
+ Features:
8
+ - Support for multiple agent frameworks (OpenAI, CrewAI, LangGraph)
9
+ - Modular architecture for easy extension
10
+ - Unified runtime environment
11
+ - CLI interface for agent interaction
12
+ """
13
+
14
+ import importlib.metadata
15
+
16
+ try:
17
+ __version__ = importlib.metadata.version("agentkernel")
18
+ except importlib.metadata.PackageNotFoundError:
19
+ __version__ = "0.1.0"
20
+
21
+ from .core import *
File without changes
@@ -0,0 +1,108 @@
1
+ import logging
2
+ import traceback
3
+ from typing import Any
4
+
5
+ from a2a.server.agent_execution import AgentExecutor, RequestContext
6
+ from a2a.server.events import EventQueue
7
+ from a2a.server.tasks import InMemoryTaskStore, TaskStore
8
+ from a2a.types import UnsupportedOperationError, AgentCard, InternalError
9
+ from a2a.utils import new_agent_text_message
10
+ from a2a.utils.errors import ServerError
11
+
12
+ from ..core import Agent, AgentService, Runtime
13
+ from ..core.config import AKConfig
14
+
15
+
16
+ class A2A:
17
+ """
18
+ A2A class provides a utility method for interacting with runtime, agents and sessions.
19
+ """
20
+ _cards: dict[str, AgentCard] = {}
21
+ """
22
+ A2A cards
23
+ """
24
+ _executors: dict[str, 'A2A.Executor'] = {}
25
+ """
26
+ A2A executors. A2A expects an executor per each agent
27
+ """
28
+ _built = False
29
+ """
30
+ Card built flag
31
+ """
32
+ _log = logging.getLogger(__name__)
33
+
34
+ class Executor(AgentExecutor):
35
+
36
+ def __init__(self, agent_name: str):
37
+ self.agent_name = agent_name
38
+ self.log = logging.getLogger(f"ak.a2a.executor.{agent_name}")
39
+
40
+ async def execute(self, context: RequestContext, event_queue: EventQueue) -> None:
41
+ if not context.task_id or not context.context_id:
42
+ raise ValueError("RequestContext must have task_id and context_id")
43
+ if not context.message:
44
+ raise ValueError("RequestContext must have a message")
45
+ try:
46
+ response = await self._execute_agent(context.context_id, context.get_user_input())
47
+ await event_queue.enqueue_event(
48
+ new_agent_text_message(str(response), context.context_id, context.task_id))
49
+ except Exception as e:
50
+ error = "Sorry, Agent Kernel encountered an error while processing your request"
51
+ self.log.error(traceback.format_exc())
52
+ self.log.error(f'Exception: {e}')
53
+ await event_queue.enqueue_event(new_agent_text_message(error, context.context_id, context.task_id))
54
+ raise ServerError(error=InternalError()) from e
55
+
56
+ async def cancel(self, context: RequestContext, event_queue: EventQueue) -> None:
57
+ raise ServerError(error=UnsupportedOperationError())
58
+
59
+ async def _execute_agent(self, session_id: str, prompt: str) -> Any:
60
+ service = AgentService()
61
+ service.select(session_id, self.agent_name)
62
+ return await service.run(prompt=prompt)
63
+
64
+ @classmethod
65
+ def _build(cls):
66
+ if cls._built:
67
+ return
68
+ if not AKConfig.get().a2a.enabled:
69
+ return
70
+ agents: dict[str, Agent] = Runtime.instance().agents()
71
+ for name, agent in agents.items():
72
+ whitelisted = AKConfig.get().a2a.agents == ["*"] or name in AKConfig.get().a2a.agents
73
+ if not whitelisted:
74
+ continue
75
+ # get card
76
+ card: AgentCard = agent.get_a2a_card()
77
+ cls._cards.update({name: card})
78
+ cls._built = True
79
+
80
+ @classmethod
81
+ def get_executor(cls, agent_name: str) -> AgentExecutor:
82
+ if cls._executors.get(agent_name) is None:
83
+ cls._executors[agent_name] = cls.Executor(agent_name)
84
+ executor: A2A.Executor = cls._executors[agent_name]
85
+ return executor
86
+
87
+ @classmethod
88
+ def get_cards(cls) -> list[AgentCard]:
89
+ cls._build()
90
+ return list(cls._cards.values())
91
+
92
+ @classmethod
93
+ def get_card(cls, name: str) -> AgentCard:
94
+ cls._build()
95
+ return cls._cards.get(name)
96
+
97
+ @classmethod
98
+ def get_agent_names(cls) -> list[str]:
99
+ cls._build()
100
+ return list(cls._cards.keys())
101
+
102
+ @classmethod
103
+ def get_task_store(cls) -> TaskStore:
104
+ return RedisTaskStore() if AKConfig.get().a2a.task_store_type == "redis" else InMemoryTaskStore()
105
+
106
+
107
+ class RedisTaskStore(InMemoryTaskStore):
108
+ pass
@@ -0,0 +1,16 @@
1
+ """
2
+ Agent Kernel support for GoogleADK Agents.
3
+
4
+ This package contains Agent Kernel support for agents built with GoogleADK Agents.
5
+ It provides the necessary classes and methods to integrate GoogleADK agents into the Agent Kernel
6
+ framework, allowing for seamless interaction and execution of GoogleADK based agents.
7
+ """
8
+
9
+ import importlib.metadata
10
+
11
+ try:
12
+ __version__ = importlib.metadata.version("agentkernel")
13
+ except importlib.metadata.PackageNotFoundError:
14
+ __version__ = "0.1.0"
15
+
16
+ from .adk import GoogleADKModule