aap-core 0.1.1.dev1__tar.gz → 0.1.3.dev1__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.
- aap_core-0.1.3.dev1/PKG-INFO +25 -0
- aap_core-0.1.3.dev1/README.md +1 -0
- aap_core-0.1.3.dev1/pyproject.toml +39 -0
- {aap_core-0.1.1.dev1 → aap_core-0.1.3.dev1}/src/aap_core/chain.py +10 -14
- {aap_core-0.1.1.dev1 → aap_core-0.1.3.dev1}/src/aap_core/orchestration.py +1 -9
- aap_core-0.1.3.dev1/src/aap_core/prompt_augmenter.py +935 -0
- aap_core-0.1.3.dev1/src/aap_core/retriever.py +230 -0
- aap_core-0.1.3.dev1/src/aap_core/thought.py +42 -0
- aap_core-0.1.1.dev1/PKG-INFO +0 -14
- aap_core-0.1.1.dev1/README.md +0 -0
- aap_core-0.1.1.dev1/pyproject.toml +0 -25
- aap_core-0.1.1.dev1/src/aap_core/prompt_enhancer.py +0 -209
- {aap_core-0.1.1.dev1 → aap_core-0.1.3.dev1}/src/aap_core/__init__.py +0 -0
- {aap_core-0.1.1.dev1 → aap_core-0.1.3.dev1}/src/aap_core/agent.py +0 -0
- {aap_core-0.1.1.dev1 → aap_core-0.1.3.dev1}/src/aap_core/guardrail.py +0 -0
- {aap_core-0.1.1.dev1 → aap_core-0.1.3.dev1}/src/aap_core/py.typed +0 -0
- {aap_core-0.1.1.dev1 → aap_core-0.1.3.dev1}/src/aap_core/types.py +0 -0
- {aap_core-0.1.1.dev1 → aap_core-0.1.3.dev1}/src/aap_core/utils.py +0 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: aap-core
|
|
3
|
+
Version: 0.1.3.dev1
|
|
4
|
+
Summary: Agent design pattern core framework
|
|
5
|
+
Keywords: agent,ai,pattern,llm
|
|
6
|
+
Author: Ly Hon Quang
|
|
7
|
+
Author-email: Ly Hon Quang <lyhonquang@gmail.com>
|
|
8
|
+
License: MIT
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
15
|
+
Classifier: Framework :: Pydantic :: 2
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Requires-Dist: a2a-sdk>=0.3.12
|
|
18
|
+
Requires-Dist: pandas>=2.0.0
|
|
19
|
+
Requires-Dist: rouge-score>=0.1.2
|
|
20
|
+
Requires-Dist: sacrebleu>=2.5.1
|
|
21
|
+
Requires-Python: >=3.10.12
|
|
22
|
+
Project-URL: Repository, https://github.com/quanghona/agent_design_pattern.git
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
|
|
25
|
+
# AI Agent Pattern (AAP)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# AI Agent Pattern (AAP)
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "aap_core"
|
|
3
|
+
version = "0.1.3.dev1"
|
|
4
|
+
description = "Agent design pattern core framework"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = { text = "MIT" }
|
|
7
|
+
keywords = ["agent", "ai", "pattern", "llm"]
|
|
8
|
+
authors = [
|
|
9
|
+
{ name = "Ly Hon Quang", email = "lyhonquang@gmail.com" }
|
|
10
|
+
]
|
|
11
|
+
requires-python = ">=3.10.12"
|
|
12
|
+
dependencies = [
|
|
13
|
+
"a2a-sdk>=0.3.12",
|
|
14
|
+
"pandas>=2.0.0",
|
|
15
|
+
"rouge-score>=0.1.2",
|
|
16
|
+
"sacrebleu>=2.5.1",
|
|
17
|
+
]
|
|
18
|
+
classifiers = [
|
|
19
|
+
"Programming Language :: Python :: 3.10",
|
|
20
|
+
"Programming Language :: Python :: 3.11",
|
|
21
|
+
"Programming Language :: Python :: 3.12",
|
|
22
|
+
"Programming Language :: Python :: 3.13",
|
|
23
|
+
"Programming Language :: Python :: 3.14",
|
|
24
|
+
"Programming Language :: Python :: 3.15",
|
|
25
|
+
"Framework :: Pydantic :: 2",
|
|
26
|
+
"Operating System :: OS Independent",
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
[project.urls]
|
|
30
|
+
Repository = "https://github.com/quanghona/agent_design_pattern.git"
|
|
31
|
+
|
|
32
|
+
[dependency-groups]
|
|
33
|
+
lint = [
|
|
34
|
+
"ruff==0.14.0",
|
|
35
|
+
]
|
|
36
|
+
|
|
37
|
+
[build-system]
|
|
38
|
+
requires = ["uv_build>=0.8.14,<0.9.0"]
|
|
39
|
+
build-backend = "uv_build"
|
|
@@ -5,9 +5,9 @@ from typing import Callable, Generic, List, Tuple
|
|
|
5
5
|
from pydantic import Field, PrivateAttr
|
|
6
6
|
|
|
7
7
|
from .guardrail import BaseGuardRail, PassGuardRail
|
|
8
|
-
from .
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
from .prompt_augmenter import (
|
|
9
|
+
BasePromptAugmenter,
|
|
10
|
+
IdentityPromptAugmenter,
|
|
11
11
|
)
|
|
12
12
|
from .types import AgentMessage, BaseChain, ChainMessage, ChainResponse
|
|
13
13
|
|
|
@@ -98,7 +98,7 @@ class BaseCausalMultiTurnsChain(BaseLLMChain, Generic[ChainMessage, ChainRespons
|
|
|
98
98
|
class TypicalLLMChain(BaseLLMChain):
|
|
99
99
|
"""
|
|
100
100
|
A LLM chain that consists of all components in a typical response generation.
|
|
101
|
-
The chain
|
|
101
|
+
The chain has 4 steps:
|
|
102
102
|
- input guardrail: validate the input message
|
|
103
103
|
- prompt enhancement: add more context to the prompt or rewrite / refine the prompt
|
|
104
104
|
- generate: generate the response. This steps should also handle the tool calling procedure and finalize the response
|
|
@@ -108,8 +108,8 @@ class TypicalLLMChain(BaseLLMChain):
|
|
|
108
108
|
default=PassGuardRail(),
|
|
109
109
|
description="validate the input message",
|
|
110
110
|
)
|
|
111
|
-
|
|
112
|
-
default=
|
|
111
|
+
prompt_augmenter: BasePromptAugmenter = Field(
|
|
112
|
+
default=IdentityPromptAugmenter(),
|
|
113
113
|
description="add more context to the prompt or rewrite / refine the prompt",
|
|
114
114
|
)
|
|
115
115
|
tools: Sequence[Callable] = Field(
|
|
@@ -128,21 +128,17 @@ class TypicalLLMChain(BaseLLMChain):
|
|
|
128
128
|
|
|
129
129
|
def invoke(self, message: AgentMessage, **kwargs) -> AgentMessage:
|
|
130
130
|
message = self.input_guardrail(message)
|
|
131
|
-
message = self.
|
|
131
|
+
message = self.prompt_augmenter(message)
|
|
132
132
|
message = self.generate(message, **kwargs)
|
|
133
133
|
message = self.output_guardrail(message)
|
|
134
134
|
return message
|
|
135
135
|
|
|
136
136
|
|
|
137
|
-
class
|
|
138
|
-
"""A prompt
|
|
137
|
+
class MetaPromptAugmenter(BasePromptAugmenter):
|
|
138
|
+
"""A prompt augmenter that use an LLM chain to rewrite the prompt."""
|
|
139
139
|
|
|
140
140
|
chain: BaseLLMChain = Field(..., description="LLM chain that rewrite the prompt")
|
|
141
141
|
|
|
142
|
-
def
|
|
142
|
+
def augment(self, message: AgentMessage, **kwargs) -> AgentMessage:
|
|
143
143
|
message = self.chain.invoke(message, **kwargs)
|
|
144
|
-
if message.execution_result != "success":
|
|
145
|
-
return message
|
|
146
|
-
_, message.query = message.responses[-1]
|
|
147
|
-
message.responses = []
|
|
148
144
|
return message
|
|
@@ -35,11 +35,6 @@ class ReflectionAgent(BaseAgent):
|
|
|
35
35
|
...,
|
|
36
36
|
description="LLM chain that perform reflection on the result of the main task",
|
|
37
37
|
)
|
|
38
|
-
task_response_key: str = Field(
|
|
39
|
-
default="context_response",
|
|
40
|
-
description="""The key of which to store the context (e.g. intermediate result) during generation.
|
|
41
|
-
Note that the key need to start with 'context_'""",
|
|
42
|
-
)
|
|
43
38
|
|
|
44
39
|
@field_validator("task_response_key")
|
|
45
40
|
@classmethod
|
|
@@ -61,11 +56,7 @@ class ReflectionAgent(BaseAgent):
|
|
|
61
56
|
return message
|
|
62
57
|
|
|
63
58
|
self.state = "reflecting"
|
|
64
|
-
task_response_key = self.task_response_key.replace("context_", "")
|
|
65
59
|
reflect_message = message.model_copy(deep=True)
|
|
66
|
-
reflect_message.context = {}
|
|
67
|
-
_, reflect_message.context[task_response_key] = reflect_message.responses[-1] # type: ignore
|
|
68
|
-
reflect_message.responses = []
|
|
69
60
|
result_message = self.chain_reflection.invoke(reflect_message, **kwargs)
|
|
70
61
|
self.state = "idle"
|
|
71
62
|
result_message.origin = self.card.name
|
|
@@ -343,6 +334,7 @@ class CoordinatorAgent(BaseAgent):
|
|
|
343
334
|
# TODO: check step dependency and parallelize steps to speed up
|
|
344
335
|
summary_steps_key = self.summary_steps_key.replace("context_", "")
|
|
345
336
|
for i, (step_msg, step_agent, dependencies) in enumerate(steps):
|
|
337
|
+
# TODO: deal with the dependencies
|
|
346
338
|
step_msg.context = {summary_steps_key: sub_task_result}
|
|
347
339
|
self.state = f"step {i}: worker {step_agent.card.name} running"
|
|
348
340
|
sub_task_result.append(step_agent.execute(step_msg, **kwargs))
|