agentkernel 0.2.9__tar.gz → 0.2.10__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.
- {agentkernel-0.2.9 → agentkernel-0.2.10}/PKG-INFO +25 -1
- {agentkernel-0.2.9 → agentkernel-0.2.10}/README.md +23 -0
- {agentkernel-0.2.9 → agentkernel-0.2.10}/pyproject.toml +3 -2
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/api/a2a/a2a.py +3 -2
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/api/handler.py +24 -3
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/api/mcp/akmcp.py +3 -2
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/core/__init__.py +2 -2
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/core/base.py +39 -0
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/core/config.py +1 -0
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/core/hooks.py +11 -6
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/core/module.py +35 -4
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/core/runtime.py +69 -140
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/core/service.py +4 -7
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/core/session/base.py +1 -1
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/framework/adk/adk.py +30 -2
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/framework/crewai/crewai.py +30 -2
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/framework/langgraph/langgraph.py +24 -1
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/framework/openai/openai.py +30 -1
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/integration/slack/README.md +11 -2
- agentkernel-0.2.10/src/agentkernel/integration/slack/slack_chat.py +307 -0
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/integration/whatsapp/README.md +13 -2
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/integration/whatsapp/whatsapp_chat.py +182 -11
- agentkernel-0.2.9/src/agentkernel/integration/slack/slack_chat.py +0 -160
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/__init__.py +0 -0
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/adk.py +0 -0
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/api/__init__.py +0 -0
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/api/a2a/__init__.py +0 -0
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/api/a2a/handler.py +0 -0
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/api/http.py +0 -0
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/api/mcp/__init__.py +0 -0
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/aws.py +0 -0
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/cli/__init__.py +0 -0
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/cli/cli.py +0 -0
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/core/builder.py +0 -0
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/core/model.py +0 -0
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/core/session/__init__.py +0 -0
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/core/session/dynamodb.py +0 -0
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/core/session/in_memory.py +0 -0
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/core/session/redis.py +0 -0
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/core/session/serde.py +0 -0
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/core/util/config_yaml_util.py +0 -0
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/core/util/key_value_cache.py +0 -0
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/crewai.py +0 -0
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/deployment/__init__.py +0 -0
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/deployment/aws/__init__.py +0 -0
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/deployment/aws/aklambda.py +0 -0
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/framework/__init__.py +0 -0
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/framework/adk/__init__.py +0 -0
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/framework/crewai/__init__.py +0 -0
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/framework/langgraph/__init__.py +0 -0
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/framework/openai/__init__.py +0 -0
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/gmail.py +0 -0
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/instagram.py +0 -0
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/integration/__init__.py +0 -0
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/integration/gmail/README.md +0 -0
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/integration/gmail/__init__.py +0 -0
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/integration/gmail/gmail_chat.py +0 -0
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/integration/instagram/README.md +0 -0
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/integration/instagram/__init__.py +0 -0
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/integration/instagram/instagram_chat.py +0 -0
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/integration/messenger/README.md +0 -0
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/integration/messenger/__init__.py +0 -0
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/integration/messenger/messenger_chat.py +0 -0
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/integration/slack/__init__.py +0 -0
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/integration/telegram/README.md +0 -0
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/integration/telegram/__init__.py +0 -0
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/integration/telegram/telegram_chat.py +0 -0
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/integration/whatsapp/__init__.py +0 -0
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/langgraph.py +0 -0
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/mcp.py +0 -0
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/messenger.py +0 -0
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/openai.py +0 -0
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/slack.py +0 -0
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/telegram.py +0 -0
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/test/__init__.py +0 -0
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/test/test.py +0 -0
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/trace/__init__.py +0 -0
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/trace/base.py +0 -0
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/trace/langfuse/__init__.py +0 -0
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/trace/langfuse/adk.py +0 -0
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/trace/langfuse/crewai.py +0 -0
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/trace/langfuse/langfuse.py +0 -0
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/trace/langfuse/langgraph.py +0 -0
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/trace/langfuse/openai.py +0 -0
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/trace/openllmetry/__init__.py +0 -0
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/trace/openllmetry/adk.py +0 -0
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/trace/openllmetry/crewai.py +0 -0
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/trace/openllmetry/langgraph.py +0 -0
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/trace/openllmetry/openai.py +0 -0
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/trace/openllmetry/openllmetry.py +0 -0
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/trace/trace.py +0 -0
- {agentkernel-0.2.9 → agentkernel-0.2.10}/src/agentkernel/whatsapp.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: agentkernel
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.10
|
|
4
4
|
Summary: Agent Kernel - Unified AI Agents Runtime
|
|
5
5
|
Author: Yaala Labs
|
|
6
6
|
Author-email: Yaala Labs <agentkernel@yaalalabs.com>
|
|
@@ -39,6 +39,7 @@ Requires-Dist: openinference-instrumentation-openai-agents>=1.4.0 ; extra == 'op
|
|
|
39
39
|
Requires-Dist: traceloop-sdk>=0.48.0 ; extra == 'openllmetry'
|
|
40
40
|
Requires-Dist: redis>=7.1.0 ; extra == 'redis'
|
|
41
41
|
Requires-Dist: slack-bolt==1.22.0 ; extra == 'slack'
|
|
42
|
+
Requires-Dist: httpx>=0.27.0 ; extra == 'slack'
|
|
42
43
|
Requires-Dist: httpx>=0.27.0 ; extra == 'telegram'
|
|
43
44
|
Requires-Dist: pytest>=8.4.1 ; extra == 'test'
|
|
44
45
|
Requires-Dist: pytest-asyncio>=1.2.0 ; extra == 'test'
|
|
@@ -577,6 +578,17 @@ Configure integrations with messaging platforms.
|
|
|
577
578
|
- **Bot Token**, **Webhook Secret**, **API Version**
|
|
578
579
|
- **Environment Variables**: `AK_TELEGRAM__BOT_TOKEN`, `AK_TELEGRAM__WEBHOOK_SECRET`, `AK_TELEGRAM__API_VERSION`
|
|
579
580
|
|
|
581
|
+
##### Gmail
|
|
582
|
+
|
|
583
|
+
- **Agent**
|
|
584
|
+
- **Field**: `gmail.agent`
|
|
585
|
+
- **Default**: `"general"`
|
|
586
|
+
- **Description**: Default agent for Gmail interactions
|
|
587
|
+
- **Environment Variable**: `AK_GMAIL__AGENT`
|
|
588
|
+
|
|
589
|
+
- **Client ID**, **Client Secret**, **Token File**, **Poll Interval**, **Label Filter**
|
|
590
|
+
- **Environment Variables**: `AK_GMAIL__CLIENT_ID`, `AK_GMAIL__CLIENT_SECRET`, `AK_GMAIL__TOKEN_FILE`, `AK_GMAIL__POLL_INTERVAL`, `AK_GMAIL__LABEL_FILTER`
|
|
591
|
+
|
|
580
592
|
### Configuration Examples
|
|
581
593
|
|
|
582
594
|
#### Environment Variables
|
|
@@ -611,6 +623,9 @@ export AK_WHATSAPP__AGENT=my-agent
|
|
|
611
623
|
export AK_MESSENGER__AGENT=my-agent
|
|
612
624
|
export AK_INSTAGRAM__AGENT=my-agent
|
|
613
625
|
export AK_TELEGRAM__AGENT=my-agent
|
|
626
|
+
export AK_GMAIL__AGENT=my-agent
|
|
627
|
+
export AK_GMAIL__CLIENT_ID=your-google-client-id
|
|
628
|
+
export AK_GMAIL__CLIENT_SECRET=your-google-client-secret
|
|
614
629
|
```
|
|
615
630
|
|
|
616
631
|
#### .env File
|
|
@@ -683,6 +698,10 @@ instagram:
|
|
|
683
698
|
agent: my-agent
|
|
684
699
|
telegram:
|
|
685
700
|
agent: my-agent
|
|
701
|
+
gmail:
|
|
702
|
+
agent: my-agent
|
|
703
|
+
poll_interval: 30
|
|
704
|
+
label_filter: "INBOX"
|
|
686
705
|
```
|
|
687
706
|
|
|
688
707
|
#### config.json
|
|
@@ -745,6 +764,11 @@ telegram:
|
|
|
745
764
|
},
|
|
746
765
|
"telegram": {
|
|
747
766
|
"agent": "my-agent"
|
|
767
|
+
},
|
|
768
|
+
"gmail": {
|
|
769
|
+
"agent": "my-agent",
|
|
770
|
+
"poll_interval": 30,
|
|
771
|
+
"label_filter": "INBOX"
|
|
748
772
|
}
|
|
749
773
|
}
|
|
750
774
|
```
|
|
@@ -502,6 +502,17 @@ Configure integrations with messaging platforms.
|
|
|
502
502
|
- **Bot Token**, **Webhook Secret**, **API Version**
|
|
503
503
|
- **Environment Variables**: `AK_TELEGRAM__BOT_TOKEN`, `AK_TELEGRAM__WEBHOOK_SECRET`, `AK_TELEGRAM__API_VERSION`
|
|
504
504
|
|
|
505
|
+
##### Gmail
|
|
506
|
+
|
|
507
|
+
- **Agent**
|
|
508
|
+
- **Field**: `gmail.agent`
|
|
509
|
+
- **Default**: `"general"`
|
|
510
|
+
- **Description**: Default agent for Gmail interactions
|
|
511
|
+
- **Environment Variable**: `AK_GMAIL__AGENT`
|
|
512
|
+
|
|
513
|
+
- **Client ID**, **Client Secret**, **Token File**, **Poll Interval**, **Label Filter**
|
|
514
|
+
- **Environment Variables**: `AK_GMAIL__CLIENT_ID`, `AK_GMAIL__CLIENT_SECRET`, `AK_GMAIL__TOKEN_FILE`, `AK_GMAIL__POLL_INTERVAL`, `AK_GMAIL__LABEL_FILTER`
|
|
515
|
+
|
|
505
516
|
### Configuration Examples
|
|
506
517
|
|
|
507
518
|
#### Environment Variables
|
|
@@ -536,6 +547,9 @@ export AK_WHATSAPP__AGENT=my-agent
|
|
|
536
547
|
export AK_MESSENGER__AGENT=my-agent
|
|
537
548
|
export AK_INSTAGRAM__AGENT=my-agent
|
|
538
549
|
export AK_TELEGRAM__AGENT=my-agent
|
|
550
|
+
export AK_GMAIL__AGENT=my-agent
|
|
551
|
+
export AK_GMAIL__CLIENT_ID=your-google-client-id
|
|
552
|
+
export AK_GMAIL__CLIENT_SECRET=your-google-client-secret
|
|
539
553
|
```
|
|
540
554
|
|
|
541
555
|
#### .env File
|
|
@@ -608,6 +622,10 @@ instagram:
|
|
|
608
622
|
agent: my-agent
|
|
609
623
|
telegram:
|
|
610
624
|
agent: my-agent
|
|
625
|
+
gmail:
|
|
626
|
+
agent: my-agent
|
|
627
|
+
poll_interval: 30
|
|
628
|
+
label_filter: "INBOX"
|
|
611
629
|
```
|
|
612
630
|
|
|
613
631
|
#### config.json
|
|
@@ -670,6 +688,11 @@ telegram:
|
|
|
670
688
|
},
|
|
671
689
|
"telegram": {
|
|
672
690
|
"agent": "my-agent"
|
|
691
|
+
},
|
|
692
|
+
"gmail": {
|
|
693
|
+
"agent": "my-agent",
|
|
694
|
+
"poll_interval": 30,
|
|
695
|
+
"label_filter": "INBOX"
|
|
673
696
|
}
|
|
674
697
|
}
|
|
675
698
|
```
|
|
@@ -4,7 +4,7 @@ build-backend = "uv_build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "agentkernel"
|
|
7
|
-
version = "0.2.
|
|
7
|
+
version = "0.2.10"
|
|
8
8
|
description = "Agent Kernel - Unified AI Agents Runtime"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.12"
|
|
@@ -63,7 +63,8 @@ api = [
|
|
|
63
63
|
"gunicorn>=23.0.0"
|
|
64
64
|
]
|
|
65
65
|
slack = [
|
|
66
|
-
"slack-bolt==1.22.0"
|
|
66
|
+
"slack-bolt==1.22.0",
|
|
67
|
+
"httpx>=0.27.0"
|
|
67
68
|
]
|
|
68
69
|
whatsapp = [
|
|
69
70
|
"httpx>=0.27.0"
|
|
@@ -9,8 +9,9 @@ from a2a.types import AgentCard, InternalError, UnsupportedOperationError
|
|
|
9
9
|
from a2a.utils import new_agent_text_message
|
|
10
10
|
from a2a.utils.errors import ServerError
|
|
11
11
|
|
|
12
|
-
from ...core import Agent, AgentService
|
|
12
|
+
from ...core import Agent, AgentService
|
|
13
13
|
from ...core.config import AKConfig
|
|
14
|
+
from ...core.runtime import Runtime
|
|
14
15
|
|
|
15
16
|
|
|
16
17
|
class A2A:
|
|
@@ -69,7 +70,7 @@ class A2A:
|
|
|
69
70
|
return
|
|
70
71
|
if not AKConfig.get().a2a.enabled:
|
|
71
72
|
return
|
|
72
|
-
agents: dict[str, Agent] =
|
|
73
|
+
agents: dict[str, Agent] = Runtime.current().agents()
|
|
73
74
|
for name, agent in agents.items():
|
|
74
75
|
whitelisted = AKConfig.get().a2a.agents == ["*"] or name in AKConfig.get().a2a.agents
|
|
75
76
|
if not whitelisted:
|
|
@@ -17,7 +17,8 @@ from agentkernel.core.model import (
|
|
|
17
17
|
AgentRequestText,
|
|
18
18
|
)
|
|
19
19
|
|
|
20
|
-
from ..core import AgentService,
|
|
20
|
+
from ..core import AgentService, Config
|
|
21
|
+
from ..core.runtime import Runtime
|
|
21
22
|
|
|
22
23
|
|
|
23
24
|
class RESTRequestHandler(ABC):
|
|
@@ -37,7 +38,8 @@ class RESTRequestHandler(ABC):
|
|
|
37
38
|
|
|
38
39
|
@router.get("/agents")
|
|
39
40
|
def list_agents():
|
|
40
|
-
|
|
41
|
+
from ..core.runtime import Runtime
|
|
42
|
+
return {"agents": list(Runtime.current().agents().keys())}
|
|
41
43
|
|
|
42
44
|
"""
|
|
43
45
|
pass
|
|
@@ -55,6 +57,7 @@ class AgentRESTRequestHandler(RESTRequestHandler):
|
|
|
55
57
|
|
|
56
58
|
def __init__(self):
|
|
57
59
|
self._log = logging.getLogger("ak.api.agent")
|
|
60
|
+
self._max_file_size = Config.get().api.max_file_size
|
|
58
61
|
|
|
59
62
|
class FileData(BaseModel):
|
|
60
63
|
"""Represents a file attachment"""
|
|
@@ -92,7 +95,7 @@ class AgentRESTRequestHandler(RESTRequestHandler):
|
|
|
92
95
|
|
|
93
96
|
@router.get("/agents")
|
|
94
97
|
def list_agents():
|
|
95
|
-
return {"agents": list(
|
|
98
|
+
return {"agents": list(Runtime.current().agents().keys())}
|
|
96
99
|
|
|
97
100
|
@router.post("/run")
|
|
98
101
|
async def run(body: AgentRESTRequestHandler.RunRequest):
|
|
@@ -224,6 +227,15 @@ class AgentRESTRequestHandler(RESTRequestHandler):
|
|
|
224
227
|
self._log.debug(f"Processing uploaded file: {file.filename}")
|
|
225
228
|
# Read file content
|
|
226
229
|
content = await file.read()
|
|
230
|
+
|
|
231
|
+
# Validate file size
|
|
232
|
+
file_size = len(content)
|
|
233
|
+
if file_size > self._max_file_size:
|
|
234
|
+
raise ValueError(
|
|
235
|
+
f"File {file.filename} exceeds maximum size of {self._max_file_size / (1024 * 1024):.2f} MB "
|
|
236
|
+
f"(size: {file_size / (1024 * 1024):.2f} MB)"
|
|
237
|
+
)
|
|
238
|
+
|
|
227
239
|
# Encode to base64
|
|
228
240
|
file_data_base64 = base64.b64encode(content).decode("utf-8")
|
|
229
241
|
|
|
@@ -245,6 +257,15 @@ class AgentRESTRequestHandler(RESTRequestHandler):
|
|
|
245
257
|
self._log.debug(f"Processing uploaded image: {image.filename}")
|
|
246
258
|
# Read image content
|
|
247
259
|
content = await image.read()
|
|
260
|
+
|
|
261
|
+
# Validate image size
|
|
262
|
+
image_size = len(content)
|
|
263
|
+
if image_size > self._max_file_size:
|
|
264
|
+
raise ValueError(
|
|
265
|
+
f"Image {image.filename} exceeds maximum size of {self._max_file_size / (1024 * 1024):.2f} MB "
|
|
266
|
+
f"(size: {image_size / (1024 * 1024):.2f} MB)"
|
|
267
|
+
)
|
|
268
|
+
|
|
248
269
|
# Encode to base64
|
|
249
270
|
image_data_base64 = base64.b64encode(content).decode("utf-8")
|
|
250
271
|
|
|
@@ -4,8 +4,9 @@ from typing import Any
|
|
|
4
4
|
from fastmcp import Context, FastMCP
|
|
5
5
|
from fastmcp.server.http import StarletteWithLifespan
|
|
6
6
|
|
|
7
|
-
from ...core import Agent, AgentService
|
|
7
|
+
from ...core import Agent, AgentService
|
|
8
8
|
from ...core.config import AKConfig
|
|
9
|
+
from ...core.runtime import Runtime
|
|
9
10
|
|
|
10
11
|
|
|
11
12
|
class MCP:
|
|
@@ -60,7 +61,7 @@ class MCP:
|
|
|
60
61
|
if cls._fastmcp is None:
|
|
61
62
|
cls._fastmcp = FastMCP("Agent Kernel FastMCP Instance")
|
|
62
63
|
if AKConfig.get().mcp.expose_agents:
|
|
63
|
-
agents: dict[str, Agent] =
|
|
64
|
+
agents: dict[str, Agent] = Runtime.current().agents()
|
|
64
65
|
for name, agent in agents.items():
|
|
65
66
|
whitelisted = AKConfig.get().mcp.agents == ["*"] or name in AKConfig.get().mcp.agents
|
|
66
67
|
if not whitelisted:
|
|
@@ -24,7 +24,7 @@ from .model import (
|
|
|
24
24
|
)
|
|
25
25
|
from .config import AKConfig as Config
|
|
26
26
|
from .module import Module
|
|
27
|
-
from .runtime import
|
|
27
|
+
from .runtime import Runtime, AuxiliaryCache
|
|
28
28
|
from .service import AgentService
|
|
29
|
-
from .hooks import
|
|
29
|
+
from .hooks import PreHook, PostHook
|
|
30
30
|
from .util.key_value_cache import KeyValueCache
|
|
@@ -3,6 +3,7 @@ import logging
|
|
|
3
3
|
from abc import ABC, abstractmethod
|
|
4
4
|
from typing import Any, List
|
|
5
5
|
|
|
6
|
+
from ..core.hooks import PostHook, PreHook
|
|
6
7
|
from .config import AKConfig
|
|
7
8
|
from .model import AgentReply, AgentRequest
|
|
8
9
|
from .util.key_value_cache import KeyValueCache
|
|
@@ -197,6 +198,8 @@ class Agent(ABC):
|
|
|
197
198
|
"""
|
|
198
199
|
self._name = name
|
|
199
200
|
self._runner = runner
|
|
201
|
+
self._pre_hooks = []
|
|
202
|
+
self._post_hooks = []
|
|
200
203
|
|
|
201
204
|
@property
|
|
202
205
|
def name(self) -> str:
|
|
@@ -212,6 +215,42 @@ class Agent(ABC):
|
|
|
212
215
|
"""
|
|
213
216
|
return self._runner
|
|
214
217
|
|
|
218
|
+
@property
|
|
219
|
+
def pre_hooks(self) -> list[PreHook]:
|
|
220
|
+
"""
|
|
221
|
+
Returns the list of pre-execution hooks registered for the agent.
|
|
222
|
+
"""
|
|
223
|
+
return self._pre_hooks
|
|
224
|
+
|
|
225
|
+
@property
|
|
226
|
+
def post_hooks(self) -> list[PostHook]:
|
|
227
|
+
"""
|
|
228
|
+
Returns the list of post-execution hooks registered for the agent.
|
|
229
|
+
"""
|
|
230
|
+
return self._post_hooks
|
|
231
|
+
|
|
232
|
+
def attach_pre_hooks(self, hooks: list[PreHook]):
|
|
233
|
+
"""
|
|
234
|
+
Attaches pre-execution hooks to the agent.
|
|
235
|
+
Duplicate hook objects are ignored to prevent multiple registrations
|
|
236
|
+
of the same hook.
|
|
237
|
+
:param hooks: List of pre-execution hooks to attach.
|
|
238
|
+
"""
|
|
239
|
+
for hook in hooks:
|
|
240
|
+
if hook not in self._pre_hooks:
|
|
241
|
+
self._pre_hooks.append(hook)
|
|
242
|
+
|
|
243
|
+
def attach_post_hooks(self, hooks: list[PostHook]):
|
|
244
|
+
"""
|
|
245
|
+
Attaches post-execution hooks to the agent.
|
|
246
|
+
Duplicate hook objects are ignored to prevent multiple registrations
|
|
247
|
+
of the same hook.
|
|
248
|
+
:param hooks: List of post-execution hooks to attach.
|
|
249
|
+
"""
|
|
250
|
+
for hook in hooks:
|
|
251
|
+
if hook not in self._post_hooks:
|
|
252
|
+
self._post_hooks.append(hook)
|
|
253
|
+
|
|
215
254
|
@staticmethod
|
|
216
255
|
def _generate_a2a_card(agent_name: str, description: str, skills: List):
|
|
217
256
|
"""
|
|
@@ -52,6 +52,7 @@ class _APIConfig(BaseModel):
|
|
|
52
52
|
port: int = Field(default=8000, description="API port")
|
|
53
53
|
enabled_routes: _RoutesConfig = Field(description="API route flags", default_factory=_RoutesConfig)
|
|
54
54
|
custom_router_prefix: str = Field(default="/custom", description="Custom router prefix")
|
|
55
|
+
max_file_size: int = Field(default=2097152, description="Maximum file size in bytes (default: 2 MB)")
|
|
55
56
|
|
|
56
57
|
|
|
57
58
|
class _A2AConfig(BaseModel):
|
|
@@ -1,20 +1,25 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
1
3
|
from abc import ABC, abstractmethod
|
|
4
|
+
from typing import TYPE_CHECKING
|
|
5
|
+
|
|
6
|
+
if TYPE_CHECKING:
|
|
7
|
+
from .base import Agent, Session
|
|
2
8
|
|
|
3
|
-
from .base import Agent, Session
|
|
4
9
|
from .model import AgentReply, AgentRequest
|
|
5
10
|
|
|
6
11
|
"""
|
|
7
|
-
|
|
12
|
+
PreHook and PostHook classes define the interface for hooks that can be executed before and after an agent's execution respectively.
|
|
8
13
|
These hooks allow for modification of prompts before execution and replies after execution, enabling functionalities such as context injection, validation, moderation, logging, and analytics.
|
|
9
14
|
|
|
10
15
|
Currently, they will get only called for the initial execution of an agent when a user prompt is provided. It's unable to hook into agent-to-agent calls within a workflow. This will be a future enhancement.
|
|
11
16
|
"""
|
|
12
17
|
|
|
13
18
|
|
|
14
|
-
class
|
|
19
|
+
class PreHook(ABC):
|
|
15
20
|
@abstractmethod
|
|
16
21
|
async def on_run(
|
|
17
|
-
self, session: Session, agent: Agent, requests: list[AgentRequest]
|
|
22
|
+
self, session: "Session", agent: "Agent", requests: list[AgentRequest]
|
|
18
23
|
) -> list[AgentRequest] | AgentReply:
|
|
19
24
|
"""
|
|
20
25
|
Hook method called before an agent starts executing a prompt. These hooks can modify the prompt or halt execution.
|
|
@@ -42,10 +47,10 @@ class Prehook(ABC):
|
|
|
42
47
|
raise NotImplementedError
|
|
43
48
|
|
|
44
49
|
|
|
45
|
-
class
|
|
50
|
+
class PostHook(ABC):
|
|
46
51
|
@abstractmethod
|
|
47
52
|
async def on_run(
|
|
48
|
-
self, session: Session, requests: list[AgentRequest], agent: Agent, agent_reply: AgentReply
|
|
53
|
+
self, session: "Session", requests: list[AgentRequest], agent: "Agent", agent_reply: AgentReply
|
|
49
54
|
) -> AgentReply:
|
|
50
55
|
"""
|
|
51
56
|
Hook method called after an agent finishes executing a prompt. These hooks can modify the agent's reply. Some use cases:
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
from abc import ABC, abstractmethod
|
|
2
2
|
from typing import Any, List
|
|
3
3
|
|
|
4
|
+
from ..core.hooks import PostHook, PreHook
|
|
4
5
|
from .base import Agent
|
|
5
|
-
from .runtime import
|
|
6
|
+
from .runtime import Runtime
|
|
6
7
|
|
|
7
8
|
|
|
8
9
|
class Module(ABC):
|
|
@@ -32,9 +33,20 @@ class Module(ABC):
|
|
|
32
33
|
Unloads and deregisters all agents in the module
|
|
33
34
|
"""
|
|
34
35
|
for agent in self._agents:
|
|
35
|
-
|
|
36
|
+
Runtime.current().deregister(agent)
|
|
36
37
|
self._agents.clear()
|
|
37
38
|
|
|
39
|
+
def get_agent(self, name: str) -> Agent | None:
|
|
40
|
+
"""
|
|
41
|
+
Returns an agent by name from the module.
|
|
42
|
+
:param name: The name of the agent to retrieve.
|
|
43
|
+
:return: The agent with the specified name, or None if not found.
|
|
44
|
+
"""
|
|
45
|
+
for agent in self._agents:
|
|
46
|
+
if agent.name == name:
|
|
47
|
+
return agent
|
|
48
|
+
return None
|
|
49
|
+
|
|
38
50
|
@abstractmethod
|
|
39
51
|
def _wrap(self, agent: Any, agents: List[Any]) -> Agent:
|
|
40
52
|
"""
|
|
@@ -45,7 +57,7 @@ class Module(ABC):
|
|
|
45
57
|
raise NotImplementedError
|
|
46
58
|
|
|
47
59
|
@abstractmethod
|
|
48
|
-
def load(self, agents: list[Any]):
|
|
60
|
+
def load(self, agents: list[Any]) -> "Module":
|
|
49
61
|
"""
|
|
50
62
|
Loads and registers all agents to the runtime by replacing the current agents.
|
|
51
63
|
:param agents: List of agents to load.
|
|
@@ -55,10 +67,29 @@ class Module(ABC):
|
|
|
55
67
|
for agent in agents:
|
|
56
68
|
try:
|
|
57
69
|
wrapped = self._wrap(agent, agents)
|
|
58
|
-
|
|
70
|
+
Runtime.current().register(wrapped)
|
|
59
71
|
registered.append(wrapped)
|
|
60
72
|
except Exception:
|
|
61
73
|
self._agents = registered
|
|
62
74
|
self.unload()
|
|
63
75
|
raise
|
|
64
76
|
self._agents = registered
|
|
77
|
+
return self
|
|
78
|
+
|
|
79
|
+
@abstractmethod
|
|
80
|
+
def pre_hook(self, agent: Any, hooks: list[PreHook]) -> "Module":
|
|
81
|
+
"""
|
|
82
|
+
Attaches pre-execution hooks to the agent.
|
|
83
|
+
:param agent: The agent to attach hooks to.
|
|
84
|
+
:param hooks: List of pre-execution hooks to attach.
|
|
85
|
+
"""
|
|
86
|
+
raise NotImplementedError
|
|
87
|
+
|
|
88
|
+
@abstractmethod
|
|
89
|
+
def post_hook(self, agent: Any, hooks: list[PostHook]) -> "Module":
|
|
90
|
+
"""
|
|
91
|
+
Attaches post-execution hooks to the agent.
|
|
92
|
+
:param agent: The agent to attach hooks to.
|
|
93
|
+
:param hooks: List of post-execution hooks to attach.
|
|
94
|
+
"""
|
|
95
|
+
raise NotImplementedError
|