waldiez 0.1.0__py3-none-any.whl
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.
Potentially problematic release.
This version of waldiez might be problematic. Click here for more details.
- waldiez/__init__.py +15 -0
- waldiez/__main__.py +6 -0
- waldiez/_version.py +3 -0
- waldiez/cli.py +162 -0
- waldiez/exporter.py +293 -0
- waldiez/exporting/__init__.py +14 -0
- waldiez/exporting/agents/__init__.py +5 -0
- waldiez/exporting/agents/agent.py +229 -0
- waldiez/exporting/agents/agent_skills.py +67 -0
- waldiez/exporting/agents/code_execution.py +67 -0
- waldiez/exporting/agents/group_manager.py +209 -0
- waldiez/exporting/agents/llm_config.py +53 -0
- waldiez/exporting/agents/rag_user/__init__.py +5 -0
- waldiez/exporting/agents/rag_user/chroma_utils.py +134 -0
- waldiez/exporting/agents/rag_user/mongo_utils.py +83 -0
- waldiez/exporting/agents/rag_user/pgvector_utils.py +93 -0
- waldiez/exporting/agents/rag_user/qdrant_utils.py +112 -0
- waldiez/exporting/agents/rag_user/rag_user.py +165 -0
- waldiez/exporting/agents/rag_user/vector_db.py +119 -0
- waldiez/exporting/agents/teachability.py +37 -0
- waldiez/exporting/agents/termination_message.py +45 -0
- waldiez/exporting/chats/__init__.py +14 -0
- waldiez/exporting/chats/chats.py +46 -0
- waldiez/exporting/chats/helpers.py +395 -0
- waldiez/exporting/chats/nested.py +264 -0
- waldiez/exporting/flow/__init__.py +5 -0
- waldiez/exporting/flow/def_main.py +37 -0
- waldiez/exporting/flow/flow.py +185 -0
- waldiez/exporting/models/__init__.py +193 -0
- waldiez/exporting/skills/__init__.py +128 -0
- waldiez/exporting/utils/__init__.py +34 -0
- waldiez/exporting/utils/comments.py +136 -0
- waldiez/exporting/utils/importing.py +267 -0
- waldiez/exporting/utils/logging_utils.py +203 -0
- waldiez/exporting/utils/method_utils.py +35 -0
- waldiez/exporting/utils/naming.py +127 -0
- waldiez/exporting/utils/object_string.py +81 -0
- waldiez/io_stream.py +181 -0
- waldiez/models/__init__.py +107 -0
- waldiez/models/agents/__init__.py +65 -0
- waldiez/models/agents/agent/__init__.py +21 -0
- waldiez/models/agents/agent/agent.py +190 -0
- waldiez/models/agents/agent/agent_data.py +162 -0
- waldiez/models/agents/agent/code_execution.py +71 -0
- waldiez/models/agents/agent/linked_skill.py +30 -0
- waldiez/models/agents/agent/nested_chat.py +73 -0
- waldiez/models/agents/agent/teachability.py +68 -0
- waldiez/models/agents/agent/termination_message.py +167 -0
- waldiez/models/agents/agents.py +129 -0
- waldiez/models/agents/assistant/__init__.py +6 -0
- waldiez/models/agents/assistant/assistant.py +41 -0
- waldiez/models/agents/assistant/assistant_data.py +29 -0
- waldiez/models/agents/group_manager/__init__.py +19 -0
- waldiez/models/agents/group_manager/group_manager.py +87 -0
- waldiez/models/agents/group_manager/group_manager_data.py +91 -0
- waldiez/models/agents/group_manager/speakers.py +211 -0
- waldiez/models/agents/rag_user/__init__.py +26 -0
- waldiez/models/agents/rag_user/rag_user.py +58 -0
- waldiez/models/agents/rag_user/rag_user_data.py +32 -0
- waldiez/models/agents/rag_user/retrieve_config.py +592 -0
- waldiez/models/agents/rag_user/vector_db_config.py +162 -0
- waldiez/models/agents/user_proxy/__init__.py +6 -0
- waldiez/models/agents/user_proxy/user_proxy.py +41 -0
- waldiez/models/agents/user_proxy/user_proxy_data.py +30 -0
- waldiez/models/chat/__init__.py +22 -0
- waldiez/models/chat/chat.py +129 -0
- waldiez/models/chat/chat_data.py +326 -0
- waldiez/models/chat/chat_message.py +304 -0
- waldiez/models/chat/chat_nested.py +160 -0
- waldiez/models/chat/chat_summary.py +110 -0
- waldiez/models/common/__init__.py +38 -0
- waldiez/models/common/base.py +63 -0
- waldiez/models/common/method_utils.py +165 -0
- waldiez/models/flow/__init__.py +9 -0
- waldiez/models/flow/flow.py +302 -0
- waldiez/models/flow/flow_data.py +87 -0
- waldiez/models/model/__init__.py +11 -0
- waldiez/models/model/model.py +169 -0
- waldiez/models/model/model_data.py +86 -0
- waldiez/models/skill/__init__.py +9 -0
- waldiez/models/skill/skill.py +129 -0
- waldiez/models/skill/skill_data.py +37 -0
- waldiez/models/waldiez.py +301 -0
- waldiez/py.typed +0 -0
- waldiez/runner.py +304 -0
- waldiez/stream/__init__.py +7 -0
- waldiez/stream/consumer.py +139 -0
- waldiez/stream/provider.py +339 -0
- waldiez/stream/server.py +412 -0
- waldiez-0.1.0.dist-info/METADATA +181 -0
- waldiez-0.1.0.dist-info/RECORD +94 -0
- waldiez-0.1.0.dist-info/WHEEL +4 -0
- waldiez-0.1.0.dist-info/entry_points.txt +2 -0
- waldiez-0.1.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"""Waldiez models package.
|
|
2
|
+
|
|
3
|
+
- Agents (Users, Assistants, Group Managers, etc.).
|
|
4
|
+
- Chat (Messages, Summaries, etc.).
|
|
5
|
+
- Model (LLM config, API type, etc.).
|
|
6
|
+
- Skill (Skills/Tools to be registered).
|
|
7
|
+
- Flow (Flow of the conversation).
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from .agents import (
|
|
11
|
+
WaldiezAgent,
|
|
12
|
+
WaldiezAgentCodeExecutionConfig,
|
|
13
|
+
WaldiezAgentData,
|
|
14
|
+
WaldiezAgentLinkedSkill,
|
|
15
|
+
WaldiezAgentNestedChat,
|
|
16
|
+
WaldiezAgentNestedChatMessage,
|
|
17
|
+
WaldiezAgents,
|
|
18
|
+
WaldiezAgentTeachability,
|
|
19
|
+
WaldiezAgentTerminationMessage,
|
|
20
|
+
WaldiezAgentType,
|
|
21
|
+
WaldiezAssistant,
|
|
22
|
+
WaldiezAssistantData,
|
|
23
|
+
WaldiezGroupManager,
|
|
24
|
+
WaldiezGroupManagerData,
|
|
25
|
+
WaldiezGroupManagerSpeakers,
|
|
26
|
+
WaldiezGroupManagerSpeakersSelectionMethod,
|
|
27
|
+
WaldiezGroupManagerSpeakersSelectionMode,
|
|
28
|
+
WaldiezGroupManagerSpeakersTransitionsType,
|
|
29
|
+
WaldiezRagUser,
|
|
30
|
+
WaldiezRagUserChunkMode,
|
|
31
|
+
WaldiezRagUserData,
|
|
32
|
+
WaldiezRagUserModels,
|
|
33
|
+
WaldiezRagUserRetrieveConfig,
|
|
34
|
+
WaldiezRagUserTask,
|
|
35
|
+
WaldiezRagUserVectorDb,
|
|
36
|
+
WaldiezRagUserVectorDbConfig,
|
|
37
|
+
WaldiezUserProxy,
|
|
38
|
+
WaldiezUserProxyData,
|
|
39
|
+
)
|
|
40
|
+
from .chat import (
|
|
41
|
+
WaldiezChat,
|
|
42
|
+
WaldiezChatData,
|
|
43
|
+
WaldiezChatMessage,
|
|
44
|
+
WaldiezChatNested,
|
|
45
|
+
WaldiezChatSummary,
|
|
46
|
+
WaldiezChatSummaryMethod,
|
|
47
|
+
)
|
|
48
|
+
from .common import METHOD_ARGS, METHOD_TYPE_HINTS, WaldiezMethodName
|
|
49
|
+
from .flow import WaldiezFlow, WaldiezFlowData
|
|
50
|
+
from .model import (
|
|
51
|
+
WaldiezModel,
|
|
52
|
+
WaldiezModelAPIType,
|
|
53
|
+
WaldiezModelData,
|
|
54
|
+
WaldiezModelPrice,
|
|
55
|
+
)
|
|
56
|
+
from .skill import WaldiezSkill, WaldiezSkillData
|
|
57
|
+
from .waldiez import Waldiez
|
|
58
|
+
|
|
59
|
+
# pylint: disable=duplicate-code
|
|
60
|
+
__all__ = [
|
|
61
|
+
"METHOD_ARGS",
|
|
62
|
+
"METHOD_TYPE_HINTS",
|
|
63
|
+
"WaldiezMethodName",
|
|
64
|
+
"Waldiez",
|
|
65
|
+
"WaldiezAgent",
|
|
66
|
+
"WaldiezAgentCodeExecutionConfig",
|
|
67
|
+
"WaldiezAgentData",
|
|
68
|
+
"WaldiezAgentLinkedSkill",
|
|
69
|
+
"WaldiezAgentNestedChat",
|
|
70
|
+
"WaldiezAgentNestedChatMessage",
|
|
71
|
+
"WaldiezAgents",
|
|
72
|
+
"WaldiezAgentTeachability",
|
|
73
|
+
"WaldiezAgentTerminationMessage",
|
|
74
|
+
"WaldiezAgentType",
|
|
75
|
+
"WaldiezAssistant",
|
|
76
|
+
"WaldiezAssistantData",
|
|
77
|
+
"WaldiezChat",
|
|
78
|
+
"WaldiezChatData",
|
|
79
|
+
"WaldiezChatSummary",
|
|
80
|
+
"WaldiezChatNested",
|
|
81
|
+
"WaldiezChatSummaryMethod",
|
|
82
|
+
"WaldiezFlow",
|
|
83
|
+
"WaldiezFlowData",
|
|
84
|
+
"WaldiezGroupManager",
|
|
85
|
+
"WaldiezGroupManagerData",
|
|
86
|
+
"WaldiezGroupManagerSpeakers",
|
|
87
|
+
"WaldiezGroupManagerSpeakersSelectionMethod",
|
|
88
|
+
"WaldiezGroupManagerSpeakersSelectionMode",
|
|
89
|
+
"WaldiezGroupManagerSpeakersTransitionsType",
|
|
90
|
+
"WaldiezChatMessage",
|
|
91
|
+
"WaldiezModel",
|
|
92
|
+
"WaldiezModelAPIType",
|
|
93
|
+
"WaldiezModelData",
|
|
94
|
+
"WaldiezModelPrice",
|
|
95
|
+
"WaldiezRagUser",
|
|
96
|
+
"WaldiezRagUserData",
|
|
97
|
+
"WaldiezSkill",
|
|
98
|
+
"WaldiezSkillData",
|
|
99
|
+
"WaldiezUserProxy",
|
|
100
|
+
"WaldiezUserProxyData",
|
|
101
|
+
"WaldiezRagUserRetrieveConfig",
|
|
102
|
+
"WaldiezRagUserTask",
|
|
103
|
+
"WaldiezRagUserChunkMode",
|
|
104
|
+
"WaldiezRagUserVectorDb",
|
|
105
|
+
"WaldiezRagUserVectorDbConfig",
|
|
106
|
+
"WaldiezRagUserModels",
|
|
107
|
+
]
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"""Agent models."""
|
|
2
|
+
|
|
3
|
+
from .agent import (
|
|
4
|
+
WaldiezAgent,
|
|
5
|
+
WaldiezAgentCodeExecutionConfig,
|
|
6
|
+
WaldiezAgentData,
|
|
7
|
+
WaldiezAgentLinkedSkill,
|
|
8
|
+
WaldiezAgentNestedChat,
|
|
9
|
+
WaldiezAgentNestedChatMessage,
|
|
10
|
+
WaldiezAgentTeachability,
|
|
11
|
+
WaldiezAgentTerminationMessage,
|
|
12
|
+
WaldiezAgentType,
|
|
13
|
+
)
|
|
14
|
+
from .agents import WaldiezAgents
|
|
15
|
+
from .assistant import WaldiezAssistant, WaldiezAssistantData
|
|
16
|
+
from .group_manager import (
|
|
17
|
+
WaldiezGroupManager,
|
|
18
|
+
WaldiezGroupManagerData,
|
|
19
|
+
WaldiezGroupManagerSpeakers,
|
|
20
|
+
WaldiezGroupManagerSpeakersSelectionMethod,
|
|
21
|
+
WaldiezGroupManagerSpeakersSelectionMode,
|
|
22
|
+
WaldiezGroupManagerSpeakersTransitionsType,
|
|
23
|
+
)
|
|
24
|
+
from .rag_user import (
|
|
25
|
+
WaldiezRagUser,
|
|
26
|
+
WaldiezRagUserChunkMode,
|
|
27
|
+
WaldiezRagUserData,
|
|
28
|
+
WaldiezRagUserModels,
|
|
29
|
+
WaldiezRagUserRetrieveConfig,
|
|
30
|
+
WaldiezRagUserTask,
|
|
31
|
+
WaldiezRagUserVectorDb,
|
|
32
|
+
WaldiezRagUserVectorDbConfig,
|
|
33
|
+
)
|
|
34
|
+
from .user_proxy import WaldiezUserProxy, WaldiezUserProxyData
|
|
35
|
+
|
|
36
|
+
__all__ = [
|
|
37
|
+
"WaldiezAgent",
|
|
38
|
+
"WaldiezAgentType",
|
|
39
|
+
"WaldiezAgents",
|
|
40
|
+
"WaldiezAssistant",
|
|
41
|
+
"WaldiezAssistantData",
|
|
42
|
+
"WaldiezAgentCodeExecutionConfig",
|
|
43
|
+
"WaldiezAgentData",
|
|
44
|
+
"WaldiezAgentLinkedSkill",
|
|
45
|
+
"WaldiezAgentNestedChat",
|
|
46
|
+
"WaldiezAgentNestedChatMessage",
|
|
47
|
+
"WaldiezAgentTeachability",
|
|
48
|
+
"WaldiezAgentTerminationMessage",
|
|
49
|
+
"WaldiezGroupManager",
|
|
50
|
+
"WaldiezGroupManagerData",
|
|
51
|
+
"WaldiezGroupManagerSpeakers",
|
|
52
|
+
"WaldiezGroupManagerSpeakersSelectionMethod",
|
|
53
|
+
"WaldiezGroupManagerSpeakersSelectionMode",
|
|
54
|
+
"WaldiezGroupManagerSpeakersTransitionsType",
|
|
55
|
+
"WaldiezRagUser",
|
|
56
|
+
"WaldiezRagUserData",
|
|
57
|
+
"WaldiezRagUserModels",
|
|
58
|
+
"WaldiezUserProxy",
|
|
59
|
+
"WaldiezUserProxyData",
|
|
60
|
+
"WaldiezRagUserRetrieveConfig",
|
|
61
|
+
"WaldiezRagUserTask",
|
|
62
|
+
"WaldiezRagUserChunkMode",
|
|
63
|
+
"WaldiezRagUserVectorDb",
|
|
64
|
+
"WaldiezRagUserVectorDbConfig",
|
|
65
|
+
]
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"""Base agent class to be inherited by all other agents."""
|
|
2
|
+
|
|
3
|
+
from .agent import WaldiezAgent, WaldiezAgentType
|
|
4
|
+
from .agent_data import WaldiezAgentData
|
|
5
|
+
from .code_execution import WaldiezAgentCodeExecutionConfig
|
|
6
|
+
from .linked_skill import WaldiezAgentLinkedSkill
|
|
7
|
+
from .nested_chat import WaldiezAgentNestedChat, WaldiezAgentNestedChatMessage
|
|
8
|
+
from .teachability import WaldiezAgentTeachability
|
|
9
|
+
from .termination_message import WaldiezAgentTerminationMessage
|
|
10
|
+
|
|
11
|
+
__all__ = [
|
|
12
|
+
"WaldiezAgent",
|
|
13
|
+
"WaldiezAgentCodeExecutionConfig",
|
|
14
|
+
"WaldiezAgentData",
|
|
15
|
+
"WaldiezAgentLinkedSkill",
|
|
16
|
+
"WaldiezAgentNestedChat",
|
|
17
|
+
"WaldiezAgentNestedChatMessage",
|
|
18
|
+
"WaldiezAgentTeachability",
|
|
19
|
+
"WaldiezAgentTerminationMessage",
|
|
20
|
+
"WaldiezAgentType",
|
|
21
|
+
]
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
"""Base agent class to be inherited by all agents."""
|
|
2
|
+
|
|
3
|
+
from typing import List
|
|
4
|
+
|
|
5
|
+
from pydantic import Field
|
|
6
|
+
from typing_extensions import Annotated, Literal
|
|
7
|
+
|
|
8
|
+
from ...common import WaldiezBase, now
|
|
9
|
+
from .agent_data import WaldiezAgentData
|
|
10
|
+
from .code_execution import WaldiezAgentCodeExecutionConfig
|
|
11
|
+
|
|
12
|
+
WaldiezAgentType = Literal["user", "assistant", "manager", "rag_user"]
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class WaldiezAgent(WaldiezBase):
|
|
16
|
+
"""Waldiez Agent.
|
|
17
|
+
|
|
18
|
+
Attributes
|
|
19
|
+
----------
|
|
20
|
+
id : str
|
|
21
|
+
The ID of the agent.
|
|
22
|
+
type : Literal["agent"]
|
|
23
|
+
The type of the "node" in a graph: "agent"
|
|
24
|
+
agent_type : Literal["user", "assistant", "manager", "rag_user"]
|
|
25
|
+
The type of the agent
|
|
26
|
+
name: str
|
|
27
|
+
The name of the agent.
|
|
28
|
+
description : str
|
|
29
|
+
The description of the agent.
|
|
30
|
+
tags : List[str]
|
|
31
|
+
Tags for this agent.
|
|
32
|
+
requirements : List[str]
|
|
33
|
+
Python requirements for the agent.
|
|
34
|
+
created_at : str
|
|
35
|
+
The date and time when the agent was created.
|
|
36
|
+
updated_at : str
|
|
37
|
+
The date and time when the agent was last updated.
|
|
38
|
+
data: WaldiezAgentData
|
|
39
|
+
The data (properties) of this agent.
|
|
40
|
+
See `waldiez.models.agents.WaldiezAgentData` for more info.
|
|
41
|
+
|
|
42
|
+
Functions
|
|
43
|
+
---------
|
|
44
|
+
validate_linked_skills(skill_ids: List[str], agent_ids: List[str])
|
|
45
|
+
Validate the skills linked to the agent.
|
|
46
|
+
validate_linked_models(model_ids: List[str])
|
|
47
|
+
Validate the models linked to the agent.
|
|
48
|
+
"""
|
|
49
|
+
|
|
50
|
+
id: Annotated[
|
|
51
|
+
str, Field(..., title="ID", description="The agents unique id")
|
|
52
|
+
]
|
|
53
|
+
type: Annotated[
|
|
54
|
+
Literal["agent"],
|
|
55
|
+
Field(
|
|
56
|
+
"agent",
|
|
57
|
+
title="Type",
|
|
58
|
+
description="The type of the 'node' in a graph.",
|
|
59
|
+
),
|
|
60
|
+
]
|
|
61
|
+
agent_type: Annotated[
|
|
62
|
+
Literal["user", "assistant", "manager", "rag_user"],
|
|
63
|
+
Field(
|
|
64
|
+
...,
|
|
65
|
+
title="Agent type",
|
|
66
|
+
description="The type of the agent: user, assistant, group manager",
|
|
67
|
+
),
|
|
68
|
+
]
|
|
69
|
+
name: Annotated[
|
|
70
|
+
str, Field(..., title="Name", description="The name of the agent")
|
|
71
|
+
]
|
|
72
|
+
description: Annotated[
|
|
73
|
+
str,
|
|
74
|
+
Field(
|
|
75
|
+
"Agent's description",
|
|
76
|
+
title="Description",
|
|
77
|
+
description="The description of the agent",
|
|
78
|
+
),
|
|
79
|
+
]
|
|
80
|
+
tags: Annotated[
|
|
81
|
+
List[str],
|
|
82
|
+
Field(
|
|
83
|
+
title="Tags",
|
|
84
|
+
description="Tags of the agent",
|
|
85
|
+
default_factory=list,
|
|
86
|
+
),
|
|
87
|
+
]
|
|
88
|
+
requirements: Annotated[
|
|
89
|
+
List[str],
|
|
90
|
+
Field(
|
|
91
|
+
title="Requirements",
|
|
92
|
+
description="Python requirements for the agent",
|
|
93
|
+
default_factory=list,
|
|
94
|
+
),
|
|
95
|
+
]
|
|
96
|
+
created_at: Annotated[
|
|
97
|
+
str,
|
|
98
|
+
Field(
|
|
99
|
+
title="Created at",
|
|
100
|
+
description="The date and time when the agent was created",
|
|
101
|
+
default_factory=now,
|
|
102
|
+
),
|
|
103
|
+
]
|
|
104
|
+
updated_at: Annotated[
|
|
105
|
+
str,
|
|
106
|
+
Field(
|
|
107
|
+
title="Updated at",
|
|
108
|
+
description="The date and time when the agent was last updated",
|
|
109
|
+
default_factory=now,
|
|
110
|
+
),
|
|
111
|
+
]
|
|
112
|
+
data: Annotated[
|
|
113
|
+
WaldiezAgentData,
|
|
114
|
+
Field(
|
|
115
|
+
title="Data",
|
|
116
|
+
description="The data (properties) of the agent",
|
|
117
|
+
default_factory=WaldiezAgentData,
|
|
118
|
+
),
|
|
119
|
+
]
|
|
120
|
+
|
|
121
|
+
def validate_linked_skills(
|
|
122
|
+
self, skill_ids: List[str], agent_ids: List[str]
|
|
123
|
+
) -> None:
|
|
124
|
+
"""Validate the skills.
|
|
125
|
+
|
|
126
|
+
Parameters
|
|
127
|
+
----------
|
|
128
|
+
skill_ids : List[str]
|
|
129
|
+
The list of skill IDs.
|
|
130
|
+
agent_ids : List[str]
|
|
131
|
+
The list of agent IDs.
|
|
132
|
+
|
|
133
|
+
Raises
|
|
134
|
+
------
|
|
135
|
+
ValueError
|
|
136
|
+
If a skill or agent is not found
|
|
137
|
+
"""
|
|
138
|
+
# if the config dict has skills, make sure they can be found
|
|
139
|
+
for skill in self.data.skills:
|
|
140
|
+
if skill.id not in skill_ids:
|
|
141
|
+
raise ValueError(
|
|
142
|
+
f"Skill '{skill.id}' not found in agent's {self.id} skills"
|
|
143
|
+
)
|
|
144
|
+
if skill.executor_id not in agent_ids:
|
|
145
|
+
raise ValueError(
|
|
146
|
+
f"Agent '{skill.executor_id}' not found in agents"
|
|
147
|
+
)
|
|
148
|
+
|
|
149
|
+
def validate_linked_models(self, model_ids: List[str]) -> None:
|
|
150
|
+
"""Validate the models.
|
|
151
|
+
|
|
152
|
+
Parameters
|
|
153
|
+
----------
|
|
154
|
+
model_ids : List[str]
|
|
155
|
+
The list of model IDs.
|
|
156
|
+
|
|
157
|
+
Raises
|
|
158
|
+
------
|
|
159
|
+
ValueError
|
|
160
|
+
If a model is not found
|
|
161
|
+
"""
|
|
162
|
+
# if the config dict has models, make sure they can be found
|
|
163
|
+
for model in self.data.model_ids:
|
|
164
|
+
if model not in model_ids:
|
|
165
|
+
raise ValueError(
|
|
166
|
+
f"Model '{model}' not found in agent's {self.id} models"
|
|
167
|
+
)
|
|
168
|
+
|
|
169
|
+
def validate_code_execution(self, skill_ids: List[str]) -> None:
|
|
170
|
+
"""Validate the code execution config.
|
|
171
|
+
|
|
172
|
+
Parameters
|
|
173
|
+
----------
|
|
174
|
+
skill_ids : List[str]
|
|
175
|
+
The list of skill IDs.
|
|
176
|
+
|
|
177
|
+
Raises
|
|
178
|
+
------
|
|
179
|
+
ValueError
|
|
180
|
+
If a function is not found
|
|
181
|
+
"""
|
|
182
|
+
# if the config dict has functions, make sure they can be found
|
|
183
|
+
if isinstance(
|
|
184
|
+
self.data.code_execution_config, WaldiezAgentCodeExecutionConfig
|
|
185
|
+
):
|
|
186
|
+
for function in self.data.code_execution_config.functions:
|
|
187
|
+
if function not in skill_ids:
|
|
188
|
+
raise ValueError(
|
|
189
|
+
f"Function '{function}' not found in skills"
|
|
190
|
+
)
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
"""Common data structures for agents."""
|
|
2
|
+
|
|
3
|
+
from typing import List, Optional, Union
|
|
4
|
+
|
|
5
|
+
from pydantic import ConfigDict, Field
|
|
6
|
+
from pydantic.alias_generators import to_camel
|
|
7
|
+
from typing_extensions import Annotated, Literal
|
|
8
|
+
|
|
9
|
+
from ...common import WaldiezBase
|
|
10
|
+
from .code_execution import WaldiezAgentCodeExecutionConfig
|
|
11
|
+
from .linked_skill import WaldiezAgentLinkedSkill
|
|
12
|
+
from .nested_chat import WaldiezAgentNestedChat
|
|
13
|
+
from .teachability import WaldiezAgentTeachability
|
|
14
|
+
from .termination_message import WaldiezAgentTerminationMessage
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class WaldiezAgentData(WaldiezBase):
|
|
18
|
+
"""Waldiez Agent Data.
|
|
19
|
+
|
|
20
|
+
Attributes
|
|
21
|
+
----------
|
|
22
|
+
system_message : Optional[str]
|
|
23
|
+
The agent's system message. Default: None (depends on the agent's type)
|
|
24
|
+
human_input_mode : Literal["ALWAYS", "NEVER", "TERMINATE"]
|
|
25
|
+
The human input mode to use for the agent.
|
|
26
|
+
code_execution_config : Union[WaldiezAgentCodeExecutionConfig, False]
|
|
27
|
+
The code execution config. Either False (no execution) or a dict
|
|
28
|
+
max_tokens : Optional[int]
|
|
29
|
+
The maximum tokens to use. Default: None (no limit).
|
|
30
|
+
agent_default_auto_reply : Optional[str]
|
|
31
|
+
The agent's default auto reply when no input is received.
|
|
32
|
+
max_consecutive_auto_reply : Optional[int]
|
|
33
|
+
The maximum number or consecutive auto replies to use
|
|
34
|
+
before ending the chat. Default: None (no limit).
|
|
35
|
+
termination : WaldiezAgentTerminationMessage
|
|
36
|
+
The message termination check to use (keyword, method, none)
|
|
37
|
+
teachability : WaldiezAgentTeachability
|
|
38
|
+
The agent teachability configuration.
|
|
39
|
+
model_ids: List[str]
|
|
40
|
+
A list of models (their ids) to link with the agent.
|
|
41
|
+
skills : List[WaldiezAgentLinkedSkill]
|
|
42
|
+
A list of skills (id and executor) to register.
|
|
43
|
+
nested_chats : List[WaldiezAgentNestedChat]
|
|
44
|
+
A list of nested chats (triggered_by, messages), to register.
|
|
45
|
+
"""
|
|
46
|
+
|
|
47
|
+
model_config = ConfigDict(
|
|
48
|
+
extra="forbid",
|
|
49
|
+
alias_generator=to_camel,
|
|
50
|
+
populate_by_name=True,
|
|
51
|
+
# we have a field starting with "model_" (model_ids)
|
|
52
|
+
# this is protected by default
|
|
53
|
+
protected_namespaces=(),
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
system_message: Annotated[
|
|
57
|
+
Optional[str],
|
|
58
|
+
Field(
|
|
59
|
+
None,
|
|
60
|
+
title="System message",
|
|
61
|
+
description="The agent's system message.",
|
|
62
|
+
alias="systemMessage",
|
|
63
|
+
),
|
|
64
|
+
]
|
|
65
|
+
human_input_mode: Annotated[
|
|
66
|
+
Literal["ALWAYS", "NEVER", "TERMINATE"],
|
|
67
|
+
Field(
|
|
68
|
+
"NEVER",
|
|
69
|
+
title="Human input mode",
|
|
70
|
+
description="The human input mode to use for the agent.",
|
|
71
|
+
alias="humanInputMode",
|
|
72
|
+
),
|
|
73
|
+
]
|
|
74
|
+
max_tokens: Annotated[
|
|
75
|
+
Optional[int],
|
|
76
|
+
Field(
|
|
77
|
+
None,
|
|
78
|
+
title="Max tokens",
|
|
79
|
+
description="The maximum tokens to use. Default: None (no limit).",
|
|
80
|
+
alias="maxTokens",
|
|
81
|
+
),
|
|
82
|
+
]
|
|
83
|
+
code_execution_config: Annotated[
|
|
84
|
+
Union[WaldiezAgentCodeExecutionConfig, Literal[False]],
|
|
85
|
+
Field(
|
|
86
|
+
False,
|
|
87
|
+
title="Code execution config",
|
|
88
|
+
description=(
|
|
89
|
+
"The code execution config. Either False (no execution) "
|
|
90
|
+
"or a `WaldiezAgentCodeExecutionConfig` with details"
|
|
91
|
+
),
|
|
92
|
+
alias="codeExecutionConfig",
|
|
93
|
+
),
|
|
94
|
+
]
|
|
95
|
+
agent_default_auto_reply: Annotated[
|
|
96
|
+
Optional[str],
|
|
97
|
+
Field(
|
|
98
|
+
None,
|
|
99
|
+
title="Agent's default auto reply",
|
|
100
|
+
description=(
|
|
101
|
+
"The agent's default auto reply when no input is received."
|
|
102
|
+
),
|
|
103
|
+
alias="agentDefaultAutoReply",
|
|
104
|
+
),
|
|
105
|
+
]
|
|
106
|
+
max_consecutive_auto_reply: Annotated[
|
|
107
|
+
Optional[int],
|
|
108
|
+
Field(
|
|
109
|
+
None,
|
|
110
|
+
title="Max consecutive auto reply",
|
|
111
|
+
description=(
|
|
112
|
+
"The maximum number or consecutive auto replies to use "
|
|
113
|
+
"before ending the chat"
|
|
114
|
+
),
|
|
115
|
+
alias="maxConsecutiveAutoReply",
|
|
116
|
+
),
|
|
117
|
+
]
|
|
118
|
+
termination: Annotated[
|
|
119
|
+
WaldiezAgentTerminationMessage,
|
|
120
|
+
Field(
|
|
121
|
+
title="Termination",
|
|
122
|
+
description=(
|
|
123
|
+
"The message termination check to use (keyword, method, none)"
|
|
124
|
+
),
|
|
125
|
+
default_factory=WaldiezAgentTerminationMessage,
|
|
126
|
+
),
|
|
127
|
+
]
|
|
128
|
+
teachability: Annotated[
|
|
129
|
+
WaldiezAgentTeachability,
|
|
130
|
+
Field(
|
|
131
|
+
title="Teachability",
|
|
132
|
+
description="The agent teachability configuration.",
|
|
133
|
+
default_factory=WaldiezAgentTeachability,
|
|
134
|
+
),
|
|
135
|
+
]
|
|
136
|
+
model_ids: Annotated[
|
|
137
|
+
List[str],
|
|
138
|
+
Field(
|
|
139
|
+
default_factory=list,
|
|
140
|
+
title="Model IDs",
|
|
141
|
+
description="A list of models (their ids) to link with the agent.",
|
|
142
|
+
alias="modelIds",
|
|
143
|
+
),
|
|
144
|
+
]
|
|
145
|
+
skills: Annotated[
|
|
146
|
+
List[WaldiezAgentLinkedSkill],
|
|
147
|
+
Field(
|
|
148
|
+
default_factory=list,
|
|
149
|
+
title="Skills",
|
|
150
|
+
description=("A list of skills (id and executor) to register."),
|
|
151
|
+
),
|
|
152
|
+
]
|
|
153
|
+
nested_chats: Annotated[
|
|
154
|
+
List[WaldiezAgentNestedChat],
|
|
155
|
+
Field(
|
|
156
|
+
default_factory=list,
|
|
157
|
+
description=(
|
|
158
|
+
"A list of nested chats (triggered_by, messages), to register."
|
|
159
|
+
),
|
|
160
|
+
alias="nestedChats",
|
|
161
|
+
),
|
|
162
|
+
]
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"""Waldiez Agent Code Execution Configuration."""
|
|
2
|
+
|
|
3
|
+
from typing import List, Optional
|
|
4
|
+
|
|
5
|
+
from pydantic import Field
|
|
6
|
+
from typing_extensions import Annotated
|
|
7
|
+
|
|
8
|
+
from ...common import WaldiezBase
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class WaldiezAgentCodeExecutionConfig(WaldiezBase):
|
|
12
|
+
"""Waldiez Agent Code Execution Configuration.
|
|
13
|
+
|
|
14
|
+
Attributes
|
|
15
|
+
----------
|
|
16
|
+
work_dir : Optional[str]
|
|
17
|
+
The working directory for the code execution.
|
|
18
|
+
use_docker : Optional[bool]
|
|
19
|
+
Run the code in a docker container.
|
|
20
|
+
timeout : Optional[float]
|
|
21
|
+
The timeout for the code execution. By default None (no timeout).
|
|
22
|
+
last_n_messages : Optional[int]
|
|
23
|
+
The chat's last n messages to consider for the code execution.
|
|
24
|
+
functions : Optional[List[str]]
|
|
25
|
+
If not using docker, a list of function ids to use.
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
work_dir: Annotated[
|
|
29
|
+
Optional[str],
|
|
30
|
+
Field(
|
|
31
|
+
None,
|
|
32
|
+
title="Working directory",
|
|
33
|
+
description="The working directory for the code execution.",
|
|
34
|
+
alias="workDir",
|
|
35
|
+
),
|
|
36
|
+
]
|
|
37
|
+
use_docker: Annotated[
|
|
38
|
+
Optional[bool],
|
|
39
|
+
Field(
|
|
40
|
+
None,
|
|
41
|
+
title="Use docker",
|
|
42
|
+
description="Run the code in a docker container.",
|
|
43
|
+
alias="useDocker",
|
|
44
|
+
),
|
|
45
|
+
]
|
|
46
|
+
timeout: Annotated[
|
|
47
|
+
Optional[float],
|
|
48
|
+
Field(
|
|
49
|
+
None,
|
|
50
|
+
title="Timeout",
|
|
51
|
+
description=(
|
|
52
|
+
"The timeout for the code execution.Default: No timeout"
|
|
53
|
+
),
|
|
54
|
+
),
|
|
55
|
+
]
|
|
56
|
+
last_n_messages: Annotated[
|
|
57
|
+
Optional[int],
|
|
58
|
+
Field(
|
|
59
|
+
None,
|
|
60
|
+
title="Last N Messages",
|
|
61
|
+
description="The number of previous messages in the chat to use.",
|
|
62
|
+
),
|
|
63
|
+
]
|
|
64
|
+
functions: Annotated[
|
|
65
|
+
List[str],
|
|
66
|
+
Field(
|
|
67
|
+
default_factory=list,
|
|
68
|
+
title="Functions",
|
|
69
|
+
description="If not using docker, the function ids to use",
|
|
70
|
+
),
|
|
71
|
+
]
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"""Waldiez Agent Skill Model."""
|
|
2
|
+
|
|
3
|
+
from pydantic import Field
|
|
4
|
+
from typing_extensions import Annotated
|
|
5
|
+
|
|
6
|
+
from ...common import WaldiezBase
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class WaldiezAgentLinkedSkill(WaldiezBase):
|
|
10
|
+
"""Waldiez Agent Linked Skill.
|
|
11
|
+
|
|
12
|
+
Attributes
|
|
13
|
+
----------
|
|
14
|
+
id : str
|
|
15
|
+
The id of the skill to use.
|
|
16
|
+
executor_id: str
|
|
17
|
+
The id of the agent to use that skill.
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
id: Annotated[
|
|
21
|
+
str, Field(..., title="ID", description="The id of the skill to use.")
|
|
22
|
+
]
|
|
23
|
+
executor_id: Annotated[
|
|
24
|
+
str,
|
|
25
|
+
Field(
|
|
26
|
+
...,
|
|
27
|
+
title="Executor ID",
|
|
28
|
+
description="The id of the agent to use that skill.",
|
|
29
|
+
),
|
|
30
|
+
]
|