swarmauri_agent_skill 0.11.0.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.
- swarmauri_agent_skill-0.11.0.dev1/LICENSE +201 -0
- swarmauri_agent_skill-0.11.0.dev1/PKG-INFO +64 -0
- swarmauri_agent_skill-0.11.0.dev1/README.md +39 -0
- swarmauri_agent_skill-0.11.0.dev1/pyproject.toml +66 -0
- swarmauri_agent_skill-0.11.0.dev1/swarmauri_agent_skill/SkillAgent.py +376 -0
- swarmauri_agent_skill-0.11.0.dev1/swarmauri_agent_skill/__init__.py +13 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [2025] [Jacob Stewart @ Swarmauri]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: swarmauri_agent_skill
|
|
3
|
+
Version: 0.11.0.dev1
|
|
4
|
+
Summary: Skill-aware agent wrapper for Swarmauri.
|
|
5
|
+
License-Expression: Apache-2.0
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Keywords: swarmauri,sdk,standards,skills,agents
|
|
8
|
+
Author: Jacob Stewart
|
|
9
|
+
Author-email: jacob@swarmauri.com
|
|
10
|
+
Requires-Python: >=3.10,<3.15
|
|
11
|
+
Classifier: Development Status :: 1 - Planning
|
|
12
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
13
|
+
Classifier: Programming Language :: Python
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Requires-Dist: swarmauri_base
|
|
20
|
+
Requires-Dist: swarmauri_core
|
|
21
|
+
Requires-Dist: swarmauri_standard
|
|
22
|
+
Requires-Dist: swarmauri_tool_skill_execution
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
|
|
25
|
+
# Swarmauri Skill Agent
|
|
26
|
+
|
|
27
|
+

|
|
28
|
+
|
|
29
|
+
SkillAgent composes skill instructions with existing Swarmauri agents.
|
|
30
|
+
|
|
31
|
+
[](https://pepy.tech/projects/swarmauri_agent_skill)
|
|
32
|
+
[](https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_agent_skill/)
|
|
33
|
+
[](https://pypi.org/project/swarmauri_agent_skill/)
|
|
34
|
+
[](https://pypi.org/project/swarmauri_agent_skill/)
|
|
35
|
+
[](https://pypi.org/project/swarmauri_agent_skill/)
|
|
36
|
+
|
|
37
|
+
## Features
|
|
38
|
+
|
|
39
|
+
- Provides a first-class Swarmauri standard component.
|
|
40
|
+
- Uses existing Swarmauri core and base contracts.
|
|
41
|
+
- Keeps skill and agent composition language-agnostic at the package boundary.
|
|
42
|
+
|
|
43
|
+
## Installation
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
uv add swarmauri_agent_skill
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
pip install swarmauri_agent_skill
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Usage
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
from swarmauri_agent_skill import SkillAgent
|
|
57
|
+
|
|
58
|
+
# SkillAgent wraps an existing AgentBase implementation.
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Contributing
|
|
62
|
+
|
|
63
|
+
This package is part of the Swarmauri SDK monorepo.
|
|
64
|
+
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# Swarmauri Skill Agent
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+
|
|
5
|
+
SkillAgent composes skill instructions with existing Swarmauri agents.
|
|
6
|
+
|
|
7
|
+
[](https://pepy.tech/projects/swarmauri_agent_skill)
|
|
8
|
+
[](https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_agent_skill/)
|
|
9
|
+
[](https://pypi.org/project/swarmauri_agent_skill/)
|
|
10
|
+
[](https://pypi.org/project/swarmauri_agent_skill/)
|
|
11
|
+
[](https://pypi.org/project/swarmauri_agent_skill/)
|
|
12
|
+
|
|
13
|
+
## Features
|
|
14
|
+
|
|
15
|
+
- Provides a first-class Swarmauri standard component.
|
|
16
|
+
- Uses existing Swarmauri core and base contracts.
|
|
17
|
+
- Keeps skill and agent composition language-agnostic at the package boundary.
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
uv add swarmauri_agent_skill
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pip install swarmauri_agent_skill
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Usage
|
|
30
|
+
|
|
31
|
+
```python
|
|
32
|
+
from swarmauri_agent_skill import SkillAgent
|
|
33
|
+
|
|
34
|
+
# SkillAgent wraps an existing AgentBase implementation.
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Contributing
|
|
38
|
+
|
|
39
|
+
This package is part of the Swarmauri SDK monorepo.
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "swarmauri_agent_skill"
|
|
3
|
+
version = "0.11.0.dev1"
|
|
4
|
+
description = "Skill-aware agent wrapper for Swarmauri."
|
|
5
|
+
license = "Apache-2.0"
|
|
6
|
+
readme = "README.md"
|
|
7
|
+
repository = "http://github.com/swarmauri/swarmauri-sdk"
|
|
8
|
+
requires-python = ">=3.10,<3.15"
|
|
9
|
+
classifiers = [
|
|
10
|
+
"Development Status :: 1 - Planning",
|
|
11
|
+
"License :: OSI Approved :: Apache Software License",
|
|
12
|
+
"Programming Language :: Python",
|
|
13
|
+
"Programming Language :: Python :: 3",
|
|
14
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
15
|
+
"Programming Language :: Python :: 3.10",
|
|
16
|
+
"Programming Language :: Python :: 3.11",
|
|
17
|
+
"Programming Language :: Python :: 3.12",
|
|
18
|
+
]
|
|
19
|
+
authors = [{ name = "Jacob Stewart", email = "jacob@swarmauri.com" }]
|
|
20
|
+
dependencies = [
|
|
21
|
+
"swarmauri_core",
|
|
22
|
+
"swarmauri_base",
|
|
23
|
+
"swarmauri_standard",
|
|
24
|
+
"swarmauri_tool_skill_execution",
|
|
25
|
+
]
|
|
26
|
+
keywords = ["swarmauri", "sdk", "standards", "skills", "agents"]
|
|
27
|
+
|
|
28
|
+
[tool.uv.sources]
|
|
29
|
+
swarmauri_core = { workspace = true }
|
|
30
|
+
swarmauri_base = { workspace = true }
|
|
31
|
+
swarmauri_standard = { workspace = true }
|
|
32
|
+
swarmauri_tool_skill_execution = { workspace = true }
|
|
33
|
+
|
|
34
|
+
[tool.pytest.ini_options]
|
|
35
|
+
norecursedirs = ["combined", "scripts"]
|
|
36
|
+
markers = [
|
|
37
|
+
"test: standard test",
|
|
38
|
+
"unit: Unit tests",
|
|
39
|
+
"i9n: Integration tests",
|
|
40
|
+
"r8n: Regression tests",
|
|
41
|
+
"timeout: mark test to timeout after X seconds",
|
|
42
|
+
]
|
|
43
|
+
timeout = 300
|
|
44
|
+
log_cli = true
|
|
45
|
+
log_cli_level = "INFO"
|
|
46
|
+
log_cli_format = "%(asctime)s [%(levelname)s] %(message)s"
|
|
47
|
+
log_cli_date_format = "%Y-%m-%d %H:%M:%S"
|
|
48
|
+
asyncio_default_fixture_loop_scope = "function"
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
[project.entry-points.'swarmauri.agents']
|
|
52
|
+
SkillAgent = "swarmauri_agent_skill:SkillAgent"
|
|
53
|
+
|
|
54
|
+
[build-system]
|
|
55
|
+
requires = ["poetry-core>=1.0.0"]
|
|
56
|
+
build-backend = "poetry.core.masonry.api"
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
[dependency-groups]
|
|
60
|
+
dev = [
|
|
61
|
+
"pytest>=8.0",
|
|
62
|
+
"pytest-asyncio>=0.24.0",
|
|
63
|
+
"pytest-timeout>=2.3.1",
|
|
64
|
+
"ruff>=0.9.9",
|
|
65
|
+
]
|
|
66
|
+
|
|
@@ -0,0 +1,376 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import asyncio
|
|
4
|
+
import inspect
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from typing import (
|
|
7
|
+
Any,
|
|
8
|
+
Dict,
|
|
9
|
+
Iterable,
|
|
10
|
+
List,
|
|
11
|
+
Literal,
|
|
12
|
+
Optional,
|
|
13
|
+
Sequence,
|
|
14
|
+
Union,
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
from pydantic import ConfigDict, Field
|
|
18
|
+
|
|
19
|
+
from swarmauri_base.ComponentBase import ComponentBase, SubclassUnion
|
|
20
|
+
from swarmauri_base.agents.AgentBase import AgentBase
|
|
21
|
+
from swarmauri_base.agents.AgentConversationMixin import AgentConversationMixin
|
|
22
|
+
from swarmauri_base.agents.AgentSystemContextMixin import (
|
|
23
|
+
AgentSystemContextMixin,
|
|
24
|
+
)
|
|
25
|
+
from swarmauri_base.conversations.ConversationBase import ConversationBase
|
|
26
|
+
from swarmauri_base.llms.LLMBase import LLMBase
|
|
27
|
+
from swarmauri_base.skills.SkillBase import SkillBase
|
|
28
|
+
from swarmauri_base.tools.ToolBase import ToolBase
|
|
29
|
+
from swarmauri_core.messages.IMessage import IMessage
|
|
30
|
+
from swarmauri_standard.conversations.MaxSystemContextConversation import (
|
|
31
|
+
MaxSystemContextConversation,
|
|
32
|
+
)
|
|
33
|
+
from swarmauri_standard.messages.HumanMessage import HumanMessage
|
|
34
|
+
from swarmauri_standard.messages.SystemMessage import SystemMessage
|
|
35
|
+
from swarmauri_standard.toolkits.Toolkit import Toolkit
|
|
36
|
+
from swarmauri_tool_skill_execution import SkillExecutionTool
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
@ComponentBase.register_type(AgentBase, "SkillAgent")
|
|
40
|
+
class SkillAgent(AgentSystemContextMixin, AgentConversationMixin, AgentBase):
|
|
41
|
+
llm: SubclassUnion[LLMBase]
|
|
42
|
+
conversation: SubclassUnion[ConversationBase] = Field(
|
|
43
|
+
default_factory=lambda: MaxSystemContextConversation(
|
|
44
|
+
system_context="", max_size=100
|
|
45
|
+
)
|
|
46
|
+
)
|
|
47
|
+
system_context: SystemMessage | str = SystemMessage(content="")
|
|
48
|
+
skills: List[SubclassUnion[SkillBase]] = Field(default_factory=list)
|
|
49
|
+
skill_execution_tool: SubclassUnion[ToolBase] = Field(
|
|
50
|
+
default_factory=SkillExecutionTool
|
|
51
|
+
)
|
|
52
|
+
turn_mode: Literal["single", "multi"] = "multi"
|
|
53
|
+
execution_mode: Literal["sequential", "concurrent"] = "sequential"
|
|
54
|
+
require_skill: bool = False
|
|
55
|
+
model_config = ConfigDict(extra="forbid", arbitrary_types_allowed=True)
|
|
56
|
+
type: Literal["SkillAgent"] = "SkillAgent"
|
|
57
|
+
|
|
58
|
+
def model_post_init(self, __context: Any) -> None:
|
|
59
|
+
self.skills = [self._hydrate_skill(item) for item in self.skills]
|
|
60
|
+
|
|
61
|
+
@staticmethod
|
|
62
|
+
def _hydrate_skill(value: Any) -> Any:
|
|
63
|
+
if isinstance(value, SkillBase) or not isinstance(value, dict):
|
|
64
|
+
return value
|
|
65
|
+
type_name = value.get("type")
|
|
66
|
+
skill_registry = SkillBase._registry.get("SkillBase", {})
|
|
67
|
+
skill_cls = skill_registry.get("subtypes", {}).get(type_name)
|
|
68
|
+
if skill_cls is None and type_name == "SkillBase":
|
|
69
|
+
skill_cls = skill_registry.get("model_cls", SkillBase)
|
|
70
|
+
return skill_cls.model_validate(value) if skill_cls else value
|
|
71
|
+
|
|
72
|
+
def exec(
|
|
73
|
+
self,
|
|
74
|
+
input_str: Optional[
|
|
75
|
+
Union[str, IMessage, Sequence[Union[str, IMessage]]]
|
|
76
|
+
] = "",
|
|
77
|
+
llm_kwargs: Optional[Dict] = None,
|
|
78
|
+
skill_names: Optional[Sequence[str]] = None,
|
|
79
|
+
) -> Any:
|
|
80
|
+
inputs = self._normalize_inputs(input_str)
|
|
81
|
+
if len(inputs) == 1:
|
|
82
|
+
return self._exec_one(
|
|
83
|
+
inputs[0], llm_kwargs=llm_kwargs, skill_names=skill_names
|
|
84
|
+
)
|
|
85
|
+
return [
|
|
86
|
+
self._exec_one(
|
|
87
|
+
item, llm_kwargs=llm_kwargs, skill_names=skill_names
|
|
88
|
+
)
|
|
89
|
+
for item in inputs
|
|
90
|
+
]
|
|
91
|
+
|
|
92
|
+
async def aexec(
|
|
93
|
+
self,
|
|
94
|
+
input_str: Optional[
|
|
95
|
+
Union[str, IMessage, Sequence[Union[str, IMessage]]]
|
|
96
|
+
] = "",
|
|
97
|
+
llm_kwargs: Optional[Dict] = None,
|
|
98
|
+
skill_names: Optional[Sequence[str]] = None,
|
|
99
|
+
) -> Any:
|
|
100
|
+
inputs = self._normalize_inputs(input_str)
|
|
101
|
+
if len(inputs) == 1:
|
|
102
|
+
return await self._aexec_one(
|
|
103
|
+
inputs[0], llm_kwargs=llm_kwargs, skill_names=skill_names
|
|
104
|
+
)
|
|
105
|
+
if self.execution_mode == "concurrent":
|
|
106
|
+
return await asyncio.gather(
|
|
107
|
+
*[
|
|
108
|
+
self._aexec_one(
|
|
109
|
+
item, llm_kwargs=llm_kwargs, skill_names=skill_names
|
|
110
|
+
)
|
|
111
|
+
for item in inputs
|
|
112
|
+
]
|
|
113
|
+
)
|
|
114
|
+
results = []
|
|
115
|
+
for item in inputs:
|
|
116
|
+
results.append(
|
|
117
|
+
await self._aexec_one(
|
|
118
|
+
item, llm_kwargs=llm_kwargs, skill_names=skill_names
|
|
119
|
+
)
|
|
120
|
+
)
|
|
121
|
+
return results
|
|
122
|
+
|
|
123
|
+
def select_skills(
|
|
124
|
+
self,
|
|
125
|
+
input_data: Union[str, IMessage],
|
|
126
|
+
skill_names: Optional[Sequence[str]] = None,
|
|
127
|
+
) -> List[SkillBase]:
|
|
128
|
+
if skill_names:
|
|
129
|
+
selected = [
|
|
130
|
+
skill
|
|
131
|
+
for skill in self.skills
|
|
132
|
+
if skill.name in set(skill_names)
|
|
133
|
+
]
|
|
134
|
+
missing = sorted(
|
|
135
|
+
set(skill_names) - {skill.name for skill in selected}
|
|
136
|
+
)
|
|
137
|
+
if missing:
|
|
138
|
+
raise ValueError(
|
|
139
|
+
f"Unknown skill name(s): {', '.join(missing)}"
|
|
140
|
+
)
|
|
141
|
+
return selected
|
|
142
|
+
|
|
143
|
+
if len(self.skills) == 1:
|
|
144
|
+
return list(self.skills)
|
|
145
|
+
|
|
146
|
+
input_text = self._input_text(input_data).lower()
|
|
147
|
+
selected = [
|
|
148
|
+
skill
|
|
149
|
+
for skill in self.skills
|
|
150
|
+
if self._skill_matches_input(skill, input_text)
|
|
151
|
+
]
|
|
152
|
+
if not selected and self.require_skill:
|
|
153
|
+
raise ValueError("No matching skill found for input")
|
|
154
|
+
return selected
|
|
155
|
+
|
|
156
|
+
def _exec_one(
|
|
157
|
+
self,
|
|
158
|
+
input_data: Union[str, IMessage],
|
|
159
|
+
llm_kwargs: Optional[Dict] = None,
|
|
160
|
+
skill_names: Optional[Sequence[str]] = None,
|
|
161
|
+
) -> Any:
|
|
162
|
+
conversation, selected_skills = self._prepare_conversation(
|
|
163
|
+
input_data, skill_names=skill_names
|
|
164
|
+
)
|
|
165
|
+
result = self.llm.predict(
|
|
166
|
+
conversation=conversation,
|
|
167
|
+
**self._llm_kwargs(selected_skills, llm_kwargs),
|
|
168
|
+
)
|
|
169
|
+
if result is not None:
|
|
170
|
+
conversation = result
|
|
171
|
+
if self.turn_mode == "multi":
|
|
172
|
+
self.conversation = conversation
|
|
173
|
+
return conversation.get_last().content
|
|
174
|
+
|
|
175
|
+
async def _aexec_one(
|
|
176
|
+
self,
|
|
177
|
+
input_data: Union[str, IMessage],
|
|
178
|
+
llm_kwargs: Optional[Dict] = None,
|
|
179
|
+
skill_names: Optional[Sequence[str]] = None,
|
|
180
|
+
) -> Any:
|
|
181
|
+
conversation, selected_skills = self._prepare_conversation(
|
|
182
|
+
input_data, skill_names=skill_names
|
|
183
|
+
)
|
|
184
|
+
result = await self.llm.apredict(
|
|
185
|
+
conversation=conversation,
|
|
186
|
+
**self._llm_kwargs(
|
|
187
|
+
selected_skills, llm_kwargs, method_name="apredict"
|
|
188
|
+
),
|
|
189
|
+
)
|
|
190
|
+
if result is not None:
|
|
191
|
+
conversation = result
|
|
192
|
+
if self.turn_mode == "multi":
|
|
193
|
+
self.conversation = conversation
|
|
194
|
+
return conversation.get_last().content
|
|
195
|
+
|
|
196
|
+
def _prepare_conversation(
|
|
197
|
+
self,
|
|
198
|
+
input_data: Union[str, IMessage],
|
|
199
|
+
skill_names: Optional[Sequence[str]] = None,
|
|
200
|
+
) -> tuple[ConversationBase, List[SkillBase]]:
|
|
201
|
+
conversation = self.conversation
|
|
202
|
+
if self.turn_mode == "single":
|
|
203
|
+
conversation = self.conversation.model_copy(deep=True)
|
|
204
|
+
conversation.clear_history()
|
|
205
|
+
|
|
206
|
+
selected_skills = self.select_skills(
|
|
207
|
+
input_data, skill_names=skill_names
|
|
208
|
+
)
|
|
209
|
+
self._apply_system_context(conversation, selected_skills)
|
|
210
|
+
conversation.add_message(self._to_message(input_data))
|
|
211
|
+
return conversation, selected_skills
|
|
212
|
+
|
|
213
|
+
def _apply_system_context(
|
|
214
|
+
self,
|
|
215
|
+
conversation: ConversationBase,
|
|
216
|
+
selected_skills: Iterable[SkillBase],
|
|
217
|
+
) -> None:
|
|
218
|
+
context_parts = [self.system_context.content]
|
|
219
|
+
skill_context = self._build_skill_context(selected_skills)
|
|
220
|
+
if skill_context:
|
|
221
|
+
context_parts.append(skill_context)
|
|
222
|
+
system_context = "\n\n".join(part for part in context_parts if part)
|
|
223
|
+
if hasattr(conversation, "system_context"):
|
|
224
|
+
conversation.system_context = SystemMessage(content=system_context)
|
|
225
|
+
elif system_context:
|
|
226
|
+
conversation.add_message(SystemMessage(content=system_context))
|
|
227
|
+
|
|
228
|
+
def execute_skill_commands(
|
|
229
|
+
self,
|
|
230
|
+
skill_name: str,
|
|
231
|
+
commands: Sequence[Sequence[str]] | Sequence[str],
|
|
232
|
+
input_text: str | None = None,
|
|
233
|
+
timeout: float | None = None,
|
|
234
|
+
mode: Literal["sequential", "concurrent"] = "sequential",
|
|
235
|
+
) -> Dict[str, Any]:
|
|
236
|
+
self.skill_execution_tool.skills = list(self.skills)
|
|
237
|
+
return self.skill_execution_tool(
|
|
238
|
+
skill_name=skill_name,
|
|
239
|
+
commands=commands,
|
|
240
|
+
input_text=input_text,
|
|
241
|
+
timeout=timeout,
|
|
242
|
+
mode=mode,
|
|
243
|
+
)
|
|
244
|
+
|
|
245
|
+
def get_skill_toolkit(
|
|
246
|
+
self, skills: Optional[Iterable[SkillBase]] = None
|
|
247
|
+
) -> Toolkit:
|
|
248
|
+
selected_skills = list(skills if skills is not None else self.skills)
|
|
249
|
+
self.skill_execution_tool.skills = selected_skills
|
|
250
|
+
toolkit = Toolkit()
|
|
251
|
+
toolkit.add_tool(self.skill_execution_tool)
|
|
252
|
+
return toolkit
|
|
253
|
+
|
|
254
|
+
def _llm_kwargs(
|
|
255
|
+
self,
|
|
256
|
+
selected_skills: Iterable[SkillBase],
|
|
257
|
+
llm_kwargs: Optional[Dict],
|
|
258
|
+
method_name: str = "predict",
|
|
259
|
+
) -> Dict:
|
|
260
|
+
kwargs = dict(llm_kwargs or {})
|
|
261
|
+
method = getattr(self.llm, method_name)
|
|
262
|
+
signature = inspect.signature(method)
|
|
263
|
+
accepts_kwargs = any(
|
|
264
|
+
parameter.kind == inspect.Parameter.VAR_KEYWORD
|
|
265
|
+
for parameter in signature.parameters.values()
|
|
266
|
+
)
|
|
267
|
+
if "toolkit" in signature.parameters or accepts_kwargs:
|
|
268
|
+
kwargs.setdefault(
|
|
269
|
+
"toolkit", self.get_skill_toolkit(selected_skills)
|
|
270
|
+
)
|
|
271
|
+
return kwargs
|
|
272
|
+
|
|
273
|
+
@classmethod
|
|
274
|
+
def _build_skill_context(cls, skills: Iterable[SkillBase]) -> str:
|
|
275
|
+
return "\n\n".join(
|
|
276
|
+
"\n".join(
|
|
277
|
+
[
|
|
278
|
+
f"# Skill: {skill.name}",
|
|
279
|
+
skill.description,
|
|
280
|
+
"",
|
|
281
|
+
skill.instructions,
|
|
282
|
+
"",
|
|
283
|
+
cls._build_resource_context(skill),
|
|
284
|
+
"",
|
|
285
|
+
(
|
|
286
|
+
"Available tool: SkillExecutionTool. Use this single "
|
|
287
|
+
"tool "
|
|
288
|
+
)(
|
|
289
|
+
"to run skill-local argv command arrays when execution " # noqa: E501
|
|
290
|
+
"is "
|
|
291
|
+
"needed."
|
|
292
|
+
),
|
|
293
|
+
]
|
|
294
|
+
).strip()
|
|
295
|
+
for skill in skills
|
|
296
|
+
)
|
|
297
|
+
|
|
298
|
+
@classmethod
|
|
299
|
+
def _build_resource_context(cls, skill: SkillBase) -> str:
|
|
300
|
+
lines = ["## Skill Resources"]
|
|
301
|
+
has_resources = False
|
|
302
|
+
for field_name in SkillBase._RESOURCE_FIELDS:
|
|
303
|
+
values = list(getattr(skill, field_name))
|
|
304
|
+
if not values:
|
|
305
|
+
continue
|
|
306
|
+
has_resources = True
|
|
307
|
+
lines.append(f"- {field_name}: {', '.join(values)}")
|
|
308
|
+
if field_name in {"agents", "references"}:
|
|
309
|
+
for value in values:
|
|
310
|
+
content = cls._read_resource_content(skill, value)
|
|
311
|
+
if content:
|
|
312
|
+
lines.append(f"\n### {field_name}/{value}\n{content}")
|
|
313
|
+
if not has_resources:
|
|
314
|
+
lines.append("- none")
|
|
315
|
+
return "\n".join(lines)
|
|
316
|
+
|
|
317
|
+
@staticmethod
|
|
318
|
+
def _read_resource_content(skill: SkillBase, resource_path: str) -> str:
|
|
319
|
+
root_path = getattr(skill, "root_path", None)
|
|
320
|
+
if not root_path:
|
|
321
|
+
return ""
|
|
322
|
+
root = Path(root_path).expanduser().resolve()
|
|
323
|
+
path = (root / resource_path).resolve()
|
|
324
|
+
try:
|
|
325
|
+
path.relative_to(root)
|
|
326
|
+
except ValueError:
|
|
327
|
+
return ""
|
|
328
|
+
if (
|
|
329
|
+
path.suffix.lower() not in {".md", ".yaml", ".yml"}
|
|
330
|
+
or not path.is_file()
|
|
331
|
+
):
|
|
332
|
+
return ""
|
|
333
|
+
return path.read_text(encoding="utf-8").strip()
|
|
334
|
+
|
|
335
|
+
@classmethod
|
|
336
|
+
def _skill_matches_input(cls, skill: SkillBase, input_text: str) -> bool:
|
|
337
|
+
candidates = [skill.name, skill.description]
|
|
338
|
+
metadata = skill.metadata or {}
|
|
339
|
+
for key in ("tags", "triggers"):
|
|
340
|
+
value = metadata.get(key)
|
|
341
|
+
if isinstance(value, str):
|
|
342
|
+
candidates.append(value)
|
|
343
|
+
elif isinstance(value, Iterable):
|
|
344
|
+
candidates.extend(str(item) for item in value)
|
|
345
|
+
return any(
|
|
346
|
+
candidate and str(candidate).lower() in input_text
|
|
347
|
+
for candidate in candidates
|
|
348
|
+
)
|
|
349
|
+
|
|
350
|
+
@staticmethod
|
|
351
|
+
def _input_text(input_data: Union[str, IMessage]) -> str:
|
|
352
|
+
if isinstance(input_data, str):
|
|
353
|
+
return input_data
|
|
354
|
+
return str(getattr(input_data, "content", ""))
|
|
355
|
+
|
|
356
|
+
@staticmethod
|
|
357
|
+
def _to_message(input_data: Union[str, IMessage]) -> IMessage:
|
|
358
|
+
if isinstance(input_data, str):
|
|
359
|
+
return HumanMessage(content=input_data)
|
|
360
|
+
if isinstance(input_data, IMessage):
|
|
361
|
+
return input_data
|
|
362
|
+
raise TypeError(
|
|
363
|
+
"Input data must be a string or an instance of Message."
|
|
364
|
+
)
|
|
365
|
+
|
|
366
|
+
@staticmethod
|
|
367
|
+
def _normalize_inputs(
|
|
368
|
+
input_data: Optional[
|
|
369
|
+
Union[str, IMessage, Sequence[Union[str, IMessage]]]
|
|
370
|
+
],
|
|
371
|
+
) -> List[Union[str, IMessage]]:
|
|
372
|
+
if input_data is None:
|
|
373
|
+
return [""]
|
|
374
|
+
if isinstance(input_data, str) or isinstance(input_data, IMessage):
|
|
375
|
+
return [input_data]
|
|
376
|
+
return list(input_data)
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
from .SkillAgent import SkillAgent
|
|
2
|
+
|
|
3
|
+
__all__ = ["SkillAgent"]
|
|
4
|
+
|
|
5
|
+
try:
|
|
6
|
+
from importlib.metadata import PackageNotFoundError, version
|
|
7
|
+
except ImportError:
|
|
8
|
+
from importlib_metadata import PackageNotFoundError, version
|
|
9
|
+
|
|
10
|
+
try:
|
|
11
|
+
__version__ = version("swarmauri_agent_skill")
|
|
12
|
+
except PackageNotFoundError:
|
|
13
|
+
__version__ = "0.0.0"
|