aigency 0.0.1rc235167702__py3-none-any.whl → 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.
- aigency/agents/client.py +78 -0
- aigency/agents/communicator.py +157 -0
- aigency/agents/executor.py +58 -2
- aigency/agents/generator.py +123 -3
- aigency/schemas/agent/agent.py +41 -3
- aigency/schemas/agent/model.py +37 -3
- aigency/schemas/agent/remote_agent.py +41 -0
- aigency/schemas/agent/skills.py +34 -2
- aigency/schemas/agent/tools.py +99 -12
- aigency/schemas/aigency_config.py +35 -1
- aigency/schemas/metadata/metadata.py +32 -2
- aigency/schemas/observability/observability.py +38 -3
- aigency/schemas/observability/phoenix.py +32 -2
- aigency/schemas/service/capabilities.py +29 -2
- aigency/schemas/service/interface.py +32 -2
- aigency/schemas/service/service.py +35 -2
- aigency/tools/generator.py +59 -8
- aigency/utils/config_service.py +82 -10
- aigency/utils/logger.py +135 -46
- aigency/utils/singleton.py +62 -1
- aigency/utils/utils.py +63 -6
- aigency-0.1.0.dist-info/METADATA +171 -0
- aigency-0.1.0.dist-info/RECORD +26 -0
- aigency-0.0.1rc235167702.dist-info/METADATA +0 -267
- aigency-0.0.1rc235167702.dist-info/RECORD +0 -23
- {aigency-0.0.1rc235167702.dist-info → aigency-0.1.0.dist-info}/WHEEL +0 -0
- {aigency-0.0.1rc235167702.dist-info → aigency-0.1.0.dist-info}/top_level.txt +0 -0
aigency/schemas/agent/skills.py
CHANGED
@@ -1,10 +1,42 @@
|
|
1
|
+
"""Agent skill definition and configuration schema.
|
2
|
+
|
3
|
+
This module defines the Skill Pydantic model for representing specific capabilities
|
4
|
+
or skills that an agent possesses within the Aigency framework. Skills define
|
5
|
+
what an agent can do and provide structured metadata about the agent's abilities.
|
6
|
+
|
7
|
+
Skills serve as descriptive components that help categorize and communicate an
|
8
|
+
agent's capabilities to other agents and systems in the A2A ecosystem.
|
9
|
+
|
10
|
+
Example:
|
11
|
+
Defining agent skills:
|
12
|
+
|
13
|
+
>>> skill = Skill(
|
14
|
+
... name="data_analysis",
|
15
|
+
... description="Analyze datasets and generate insights",
|
16
|
+
... tags=["analytics"]
|
17
|
+
... )
|
18
|
+
|
19
|
+
Attributes:
|
20
|
+
None: This module contains only Pydantic model definitions.
|
21
|
+
"""
|
22
|
+
|
1
23
|
from pydantic import BaseModel
|
2
24
|
from typing import List
|
3
25
|
|
26
|
+
|
4
27
|
class Skill(BaseModel):
|
5
|
-
"""Define
|
28
|
+
"""Define a specific skill of the agent.
|
29
|
+
|
30
|
+
Attributes:
|
31
|
+
id (str): Unique identifier for the skill.
|
32
|
+
name (str): Human-readable name of the skill.
|
33
|
+
description (str): Detailed description of what the skill does.
|
34
|
+
tags (List[str]): List of tags for categorizing the skill.
|
35
|
+
examples (List[str]): List of usage examples for the skill.
|
36
|
+
"""
|
37
|
+
|
6
38
|
id: str
|
7
39
|
name: str
|
8
40
|
description: str
|
9
41
|
tags: List[str]
|
10
|
-
examples: List[str]
|
42
|
+
examples: List[str]
|
aigency/schemas/agent/tools.py
CHANGED
@@ -1,39 +1,126 @@
|
|
1
|
-
"""Tool
|
1
|
+
"""Tool configuration schemas for agent capabilities.
|
2
|
+
|
3
|
+
This module defines comprehensive Pydantic models for configuring various types
|
4
|
+
of tools that agents can use within the Aigency framework. It supports multiple
|
5
|
+
tool types including MCP (Model Context Protocol) tools and function-based tools,
|
6
|
+
with specific configuration schemas for each type.
|
7
|
+
|
8
|
+
The module provides a flexible and extensible tool configuration system that
|
9
|
+
allows agents to integrate with different tool providers and execution environments,
|
10
|
+
enabling rich agent capabilities through external tool integration.
|
11
|
+
|
12
|
+
Example:
|
13
|
+
Configuring different tool types:
|
14
|
+
|
15
|
+
>>> function_tool = FunctionTool(
|
16
|
+
... type=ToolType.FUNCTION,
|
17
|
+
... name="calculator",
|
18
|
+
... module_path="math_tools",
|
19
|
+
... function_name="add"
|
20
|
+
... )
|
21
|
+
>>> mcp_tool = McpTool(
|
22
|
+
... type=ToolType.MCP,
|
23
|
+
... name="file_manager",
|
24
|
+
... mcp_config=McpTypeStdio(command="file-server")
|
25
|
+
... )
|
26
|
+
|
27
|
+
Attributes:
|
28
|
+
None: This module contains only Pydantic model definitions and enums.
|
29
|
+
"""
|
2
30
|
|
3
31
|
from enum import Enum
|
4
|
-
from typing import Dict, List, Optional
|
32
|
+
from typing import Dict, List, Optional, TypeAlias
|
5
33
|
|
6
34
|
from pydantic import BaseModel
|
7
35
|
|
8
36
|
|
9
37
|
class ToolType(str, Enum):
|
10
|
-
"""Enum for tool types.
|
38
|
+
"""Enum for tool types.
|
39
|
+
|
40
|
+
Defines the available types of tools that can be used by agents.
|
41
|
+
|
42
|
+
Attributes:
|
43
|
+
MCP: MCP (Model Context Protocol) based tools.
|
44
|
+
FUNCTION: Function-based tools loaded from Python modules.
|
45
|
+
"""
|
46
|
+
|
11
47
|
MCP = "mcp"
|
12
48
|
FUNCTION = "function"
|
13
49
|
|
14
|
-
|
15
|
-
|
50
|
+
|
51
|
+
class BaseTool(BaseModel):
|
52
|
+
"""Define an external tool that the agent can use.
|
53
|
+
|
54
|
+
Base class for all tool configurations containing common attributes.
|
55
|
+
|
56
|
+
Attributes:
|
57
|
+
type (ToolType): The type of tool (MCP or FUNCTION).
|
58
|
+
name (str): Name identifier for the tool.
|
59
|
+
description (str): Human-readable description of what the tool does.
|
60
|
+
"""
|
61
|
+
|
16
62
|
type: ToolType
|
17
63
|
name: str
|
18
64
|
description: str
|
19
65
|
|
20
|
-
|
21
|
-
|
66
|
+
|
67
|
+
class FunctionTool(BaseTool):
|
68
|
+
"""Configuration for function-based tools.
|
69
|
+
|
70
|
+
Tools that are loaded from Python functions in specified modules.
|
71
|
+
|
72
|
+
Attributes:
|
73
|
+
module_path (str): Python module path containing the function.
|
74
|
+
function_name (str): Name of the function to load from the module.
|
75
|
+
"""
|
76
|
+
|
22
77
|
module_path: str
|
23
78
|
function_name: str
|
24
79
|
|
80
|
+
|
25
81
|
class McpTypeStreamable(BaseModel):
|
26
|
-
"""Model for streamable tool type.
|
82
|
+
"""Model for streamable tool type.
|
83
|
+
|
84
|
+
Configuration for MCP tools that communicate via HTTP streaming.
|
85
|
+
|
86
|
+
Attributes:
|
87
|
+
url (str): Base URL for the MCP server.
|
88
|
+
port (int): Port number for the MCP server.
|
89
|
+
path (str): URL path for the MCP endpoint. Defaults to "/".
|
90
|
+
"""
|
91
|
+
|
27
92
|
url: str
|
28
93
|
port: int
|
29
94
|
path: str = "/"
|
30
95
|
|
96
|
+
|
31
97
|
class McpTypeStdio(BaseModel):
|
32
|
-
"""Model for stdio tool type.
|
98
|
+
"""Model for stdio tool type.
|
99
|
+
|
100
|
+
Configuration for MCP tools that communicate via standard input/output.
|
101
|
+
|
102
|
+
Attributes:
|
103
|
+
command (str): Command to execute for the MCP server.
|
104
|
+
args (List[str]): Command line arguments for the MCP server.
|
105
|
+
env (Dict[str, str], optional): Environment variables for the MCP server.
|
106
|
+
"""
|
107
|
+
|
33
108
|
command: str
|
34
109
|
args: List[str]
|
35
110
|
env: Optional[Dict[str, str]] = None
|
36
111
|
|
37
|
-
|
38
|
-
|
39
|
-
|
112
|
+
|
113
|
+
class McpTool(BaseTool):
|
114
|
+
"""Configuration for MCP-based tools.
|
115
|
+
|
116
|
+
Tools that use the Model Context Protocol for communication.
|
117
|
+
|
118
|
+
Attributes:
|
119
|
+
mcp_config (McpTypeStreamable | McpTypeStdio): Configuration for the MCP
|
120
|
+
connection, either streamable HTTP or stdio based.
|
121
|
+
"""
|
122
|
+
|
123
|
+
mcp_config: McpTypeStreamable | McpTypeStdio
|
124
|
+
|
125
|
+
|
126
|
+
Tool: TypeAlias = FunctionTool | McpTool
|
@@ -1,3 +1,25 @@
|
|
1
|
+
"""Root configuration model for Aigency agents.
|
2
|
+
|
3
|
+
This module defines the main configuration schema for Aigency agents using Pydantic
|
4
|
+
models. It provides a comprehensive structure that encompasses all aspects of agent
|
5
|
+
configuration including metadata, service settings, agent logic, and observability.
|
6
|
+
|
7
|
+
The AigencyConfig class serves as the root model that validates and structures
|
8
|
+
agent configurations loaded from YAML files, ensuring type safety and proper
|
9
|
+
validation of all configuration parameters.
|
10
|
+
|
11
|
+
Example:
|
12
|
+
Loading and using agent configuration:
|
13
|
+
|
14
|
+
>>> config_data = yaml.safe_load(open("agent.yaml"))
|
15
|
+
>>> config = AigencyConfig(**config_data)
|
16
|
+
>>> agent_name = config.metadata.name
|
17
|
+
>>> model_name = config.agent.model.name
|
18
|
+
|
19
|
+
Attributes:
|
20
|
+
None: This module contains only Pydantic model definitions.
|
21
|
+
"""
|
22
|
+
|
1
23
|
from pydantic import BaseModel
|
2
24
|
from typing import Optional
|
3
25
|
from aigency.schemas.observability.observability import Observability
|
@@ -5,8 +27,20 @@ from aigency.schemas.metadata.metadata import Metadata
|
|
5
27
|
from aigency.schemas.agent.agent import Agent
|
6
28
|
from aigency.schemas.service.service import Service
|
7
29
|
|
30
|
+
|
8
31
|
class AigencyConfig(BaseModel):
|
9
|
-
"""Root Pydantic model for complete agent configuration.
|
32
|
+
"""Root Pydantic model for complete agent configuration.
|
33
|
+
|
34
|
+
This is the main configuration model that encompasses all aspects of an
|
35
|
+
agent's setup including metadata, service configuration, agent logic,
|
36
|
+
and observability settings.
|
37
|
+
|
38
|
+
Attributes:
|
39
|
+
metadata (Metadata): Descriptive information about the agent.
|
40
|
+
service (Service): Network and communication configuration.
|
41
|
+
agent (Agent): Core agent logic, model, and capabilities.
|
42
|
+
observability (Observability, optional): Monitoring and observability settings.
|
43
|
+
"""
|
10
44
|
|
11
45
|
metadata: Metadata
|
12
46
|
service: Service
|
@@ -1,8 +1,38 @@
|
|
1
|
+
"""Agent metadata and descriptive information schema.
|
2
|
+
|
3
|
+
This module defines the Metadata Pydantic model for storing descriptive information
|
4
|
+
about agents in the Aigency framework. It provides structured metadata that helps
|
5
|
+
identify, categorize, and describe agents within the system.
|
6
|
+
|
7
|
+
The metadata includes essential information such as agent names, descriptions,
|
8
|
+
versions, and other descriptive attributes that facilitate agent discovery,
|
9
|
+
management, and documentation.
|
10
|
+
|
11
|
+
Example:
|
12
|
+
Creating agent metadata:
|
13
|
+
|
14
|
+
>>> metadata = Metadata(
|
15
|
+
... name="data_analyst",
|
16
|
+
... description="Analyzes data and generates reports",
|
17
|
+
... version="1.0.0",
|
18
|
+
... )
|
19
|
+
|
20
|
+
Attributes:
|
21
|
+
None: This module contains only Pydantic model definitions.
|
22
|
+
"""
|
23
|
+
|
1
24
|
from pydantic import BaseModel
|
2
25
|
|
3
26
|
|
4
27
|
class Metadata(BaseModel):
|
5
|
-
"""
|
28
|
+
"""Descriptive metadata of the agent.
|
29
|
+
|
30
|
+
Attributes:
|
31
|
+
name (str): Name of the agent.
|
32
|
+
version (str): Version identifier of the agent.
|
33
|
+
description (str): Human-readable description of the agent's purpose.
|
34
|
+
"""
|
35
|
+
|
6
36
|
name: str
|
7
37
|
version: str
|
8
|
-
description: str
|
38
|
+
description: str
|
@@ -1,10 +1,45 @@
|
|
1
|
+
"""Observability and monitoring configuration schemas.
|
2
|
+
|
3
|
+
This module defines Pydantic models for configuring observability and monitoring
|
4
|
+
capabilities within the Aigency framework. It provides structured configuration
|
5
|
+
for various monitoring systems and observability tools that help track agent
|
6
|
+
performance, behavior, and system health.
|
7
|
+
|
8
|
+
The observability configuration enables comprehensive monitoring of agent
|
9
|
+
operations, including metrics collection, logging, tracing, and integration
|
10
|
+
with external monitoring platforms.
|
11
|
+
|
12
|
+
Example:
|
13
|
+
Configuring observability settings:
|
14
|
+
|
15
|
+
>>> monitoring = Monitoring(phoenix=Phoenix(enabled=True, metrics_endpoint="/metrics"))
|
16
|
+
>>> observability = Observability(
|
17
|
+
... monitoring=monitoring
|
18
|
+
... )
|
19
|
+
|
20
|
+
Attributes:
|
21
|
+
None: This module contains only Pydantic model definitions.
|
22
|
+
"""
|
23
|
+
|
1
24
|
from pydantic import BaseModel
|
2
25
|
from aigency.schemas.observability.phoenix import Phoenix
|
3
26
|
|
27
|
+
|
4
28
|
class Monitoring(BaseModel):
|
5
|
-
"""
|
29
|
+
"""Configuration for monitoring tools.
|
30
|
+
|
31
|
+
Attributes:
|
32
|
+
phoenix (Phoenix): Phoenix monitoring configuration.
|
33
|
+
"""
|
34
|
+
|
6
35
|
phoenix: Phoenix
|
7
36
|
|
37
|
+
|
8
38
|
class Observability(BaseModel):
|
9
|
-
"""
|
10
|
-
|
39
|
+
"""Groups all observability configurations.
|
40
|
+
|
41
|
+
Attributes:
|
42
|
+
monitoring (Monitoring): Monitoring tools configuration.
|
43
|
+
"""
|
44
|
+
|
45
|
+
monitoring: Monitoring
|
@@ -1,6 +1,36 @@
|
|
1
|
+
"""Phoenix monitoring system configuration schema.
|
2
|
+
|
3
|
+
This module defines the Phoenix Pydantic model for configuring Phoenix monitoring
|
4
|
+
integration within the Aigency framework. Phoenix is a monitoring and observability
|
5
|
+
platform that provides insights into agent behavior, performance metrics, and
|
6
|
+
system health monitoring.
|
7
|
+
|
8
|
+
The Phoenix configuration enables agents to integrate with Phoenix monitoring
|
9
|
+
services, allowing for comprehensive tracking and analysis of agent operations
|
10
|
+
in production environments.
|
11
|
+
|
12
|
+
Example:
|
13
|
+
Configuring Phoenix monitoring:
|
14
|
+
|
15
|
+
>>> phoenix = Phoenix(
|
16
|
+
... host="phoenix",
|
17
|
+
... port=6006
|
18
|
+
... )
|
19
|
+
|
20
|
+
Attributes:
|
21
|
+
None: This module contains only Pydantic model definitions.
|
22
|
+
"""
|
23
|
+
|
1
24
|
from pydantic import BaseModel
|
2
25
|
|
26
|
+
|
3
27
|
class Phoenix(BaseModel):
|
4
|
-
"""
|
28
|
+
"""Configuration for Phoenix monitor.
|
29
|
+
|
30
|
+
Attributes:
|
31
|
+
host (str): Hostname or IP address for Phoenix monitoring service.
|
32
|
+
port (int): Port number for Phoenix monitoring service.
|
33
|
+
"""
|
34
|
+
|
5
35
|
host: str
|
6
|
-
port: int
|
36
|
+
port: int
|
@@ -1,5 +1,32 @@
|
|
1
|
+
"""Service capability configuration schema.
|
2
|
+
|
3
|
+
This module defines the Capabilities Pydantic model for configuring service
|
4
|
+
capabilities within the Aigency framework. It provides structured configuration
|
5
|
+
for defining what capabilities a service or agent can provide to other components
|
6
|
+
in the system.
|
7
|
+
|
8
|
+
The capabilities configuration helps establish service contracts and enables
|
9
|
+
proper service discovery and integration within the distributed agent ecosystem.
|
10
|
+
|
11
|
+
Example:
|
12
|
+
Configuring service capabilities:
|
13
|
+
|
14
|
+
>>> capabilities = Capabilities(
|
15
|
+
... streaming=True
|
16
|
+
... )
|
17
|
+
|
18
|
+
Attributes:
|
19
|
+
None: This module contains only Pydantic model definitions.
|
20
|
+
"""
|
21
|
+
|
1
22
|
from pydantic import BaseModel
|
2
23
|
|
24
|
+
|
3
25
|
class Capabilities(BaseModel):
|
4
|
-
"""
|
5
|
-
|
26
|
+
"""Technical capabilities of the agent service.
|
27
|
+
|
28
|
+
Attributes:
|
29
|
+
streaming (bool): Whether the agent supports streaming responses.
|
30
|
+
"""
|
31
|
+
|
32
|
+
streaming: bool
|
@@ -1,7 +1,37 @@
|
|
1
|
+
"""Service interface configuration schema.
|
2
|
+
|
3
|
+
This module defines the Interface Pydantic model for configuring service
|
4
|
+
interfaces within the Aigency framework. It provides structured configuration
|
5
|
+
for defining how services expose their functionality and communicate with
|
6
|
+
other components in the system.
|
7
|
+
|
8
|
+
The interface configuration establishes the communication protocols, endpoints,
|
9
|
+
and interaction patterns that services use to integrate with the broader
|
10
|
+
agent ecosystem.
|
11
|
+
|
12
|
+
Example:
|
13
|
+
Configuring service interface:
|
14
|
+
|
15
|
+
>>> interface = Interface(
|
16
|
+
... default_input_modes=["text/plain"],
|
17
|
+
... default_output_modes=["text/plain"]
|
18
|
+
... )
|
19
|
+
|
20
|
+
Attributes:
|
21
|
+
None: This module contains only Pydantic model definitions.
|
22
|
+
"""
|
23
|
+
|
1
24
|
from typing import List
|
2
25
|
from pydantic import BaseModel
|
3
26
|
|
27
|
+
|
4
28
|
class Interface(BaseModel):
|
5
|
-
"""Define
|
29
|
+
"""Define the agent's communication modes.
|
30
|
+
|
31
|
+
Attributes:
|
32
|
+
default_input_modes (List[str]): List of supported input communication modes.
|
33
|
+
default_output_modes (List[str]): List of supported output communication modes.
|
34
|
+
"""
|
35
|
+
|
6
36
|
default_input_modes: List[str]
|
7
|
-
default_output_modes: List[str]
|
37
|
+
default_output_modes: List[str]
|
@@ -1,9 +1,42 @@
|
|
1
|
+
"""Service network and communication configuration schema.
|
2
|
+
|
3
|
+
This module defines the Service Pydantic model for configuring service-level
|
4
|
+
settings within the Aigency framework. It provides structured configuration
|
5
|
+
for network communication, service discovery, and integration parameters
|
6
|
+
that enable agents to operate as distributed services.
|
7
|
+
|
8
|
+
The service configuration encompasses network settings, communication protocols,
|
9
|
+
and service-specific parameters that facilitate agent deployment and operation
|
10
|
+
in distributed environments.
|
11
|
+
|
12
|
+
Example:
|
13
|
+
Configuring service settings:
|
14
|
+
|
15
|
+
>>> service = Service(
|
16
|
+
... interface=Interface(default_input_modes=["text/plain"]),
|
17
|
+
... capabilities=Capabilities(streaming=True),
|
18
|
+
... host="0.0.0.0",
|
19
|
+
... port=8080
|
20
|
+
... )
|
21
|
+
|
22
|
+
Attributes:
|
23
|
+
None: This module contains only Pydantic model definitions.
|
24
|
+
"""
|
25
|
+
|
1
26
|
from pydantic import BaseModel
|
2
27
|
from aigency.schemas.service.interface import Interface
|
3
28
|
from aigency.schemas.service.capabilities import Capabilities
|
4
29
|
|
30
|
+
|
5
31
|
class Service(BaseModel):
|
6
|
-
"""
|
32
|
+
"""Network and communication configuration of the agent.
|
33
|
+
|
34
|
+
Attributes:
|
35
|
+
url (str): Base URL where the agent service is accessible.
|
36
|
+
interface (Interface): Communication interface configuration.
|
37
|
+
capabilities (Capabilities): Technical capabilities of the service.
|
38
|
+
"""
|
39
|
+
|
7
40
|
url: str
|
8
41
|
interface: Interface
|
9
|
-
capabilities: Capabilities
|
42
|
+
capabilities: Capabilities
|
aigency/tools/generator.py
CHANGED
@@ -1,7 +1,24 @@
|
|
1
|
-
"""Tool
|
1
|
+
"""Tool factory for dynamically loading and managing agent tools.
|
2
2
|
|
3
3
|
This module provides a flexible way to load different types of tools based on
|
4
|
-
configuration
|
4
|
+
configuration using the Strategy pattern and Pydantic for validation. It supports
|
5
|
+
both MCP (Model Context Protocol) tools and function-based tools, handling their
|
6
|
+
instantiation and configuration automatically.
|
7
|
+
|
8
|
+
The ToolGenerator class uses a strategy-based approach to delegate tool creation
|
9
|
+
to specialized loading functions based on the tool type, providing a clean and
|
10
|
+
extensible architecture for tool management.
|
11
|
+
|
12
|
+
Example:
|
13
|
+
Creating tools from configuration:
|
14
|
+
|
15
|
+
>>> tool_config = FunctionTool(type=ToolType.FUNCTION, name="calculator",
|
16
|
+
... module_path="math_tools", function_name="add")
|
17
|
+
>>> tool = ToolGenerator.create_tool(tool_config)
|
18
|
+
>>> result = tool(2, 3)
|
19
|
+
|
20
|
+
Attributes:
|
21
|
+
None: This module contains only class definitions and strategy mappings.
|
5
22
|
"""
|
6
23
|
|
7
24
|
import importlib
|
@@ -26,11 +43,32 @@ from aigency.utils.utils import expand_env_vars
|
|
26
43
|
|
27
44
|
|
28
45
|
class ToolGenerator:
|
29
|
-
"""Generator for creating tools based on configuration.
|
46
|
+
"""Generator for creating tools based on configuration.
|
47
|
+
|
48
|
+
This class provides static methods to dynamically load and create different
|
49
|
+
types of tools (MCP and Function tools) based on their configuration using
|
50
|
+
the Strategy pattern.
|
51
|
+
|
52
|
+
Attributes:
|
53
|
+
STRATEGIES (dict): Dictionary mapping tool types to their loading functions.
|
54
|
+
"""
|
30
55
|
|
31
56
|
@staticmethod
|
32
57
|
def load_function_tool(config: FunctionTool) -> Any:
|
33
|
-
"""Load a function tool from configuration.
|
58
|
+
"""Load a function tool from configuration.
|
59
|
+
|
60
|
+
Dynamically imports a Python module and retrieves the specified function
|
61
|
+
to use as a tool.
|
62
|
+
|
63
|
+
Args:
|
64
|
+
config (FunctionTool): Configuration containing module path and function name.
|
65
|
+
|
66
|
+
Returns:
|
67
|
+
Any: The loaded function object.
|
68
|
+
|
69
|
+
Raises:
|
70
|
+
ValueError: If the module cannot be imported or function not found.
|
71
|
+
"""
|
34
72
|
try:
|
35
73
|
module = importlib.import_module(config.module_path)
|
36
74
|
return getattr(module, config.function_name)
|
@@ -39,7 +77,16 @@ class ToolGenerator:
|
|
39
77
|
|
40
78
|
@staticmethod
|
41
79
|
def load_mcp_tool(config: McpTool) -> Any:
|
42
|
-
"""Load an MCP tool from configuration.
|
80
|
+
"""Load an MCP tool from configuration.
|
81
|
+
|
82
|
+
Creates an MCP toolset based on the connection type (streamable HTTP or stdio).
|
83
|
+
|
84
|
+
Args:
|
85
|
+
config (McpTool): Configuration containing MCP connection details.
|
86
|
+
|
87
|
+
Returns:
|
88
|
+
Any: The created MCPToolset instance.
|
89
|
+
"""
|
43
90
|
|
44
91
|
if isinstance(config.mcp_config, McpTypeStreamable):
|
45
92
|
url = f"http://{config.mcp_config.url}:{config.mcp_config.port}{config.mcp_config.path}"
|
@@ -66,14 +113,18 @@ class ToolGenerator:
|
|
66
113
|
def create_tool(tool: Tool) -> Optional[Any]:
|
67
114
|
"""Create a tool based on its configuration.
|
68
115
|
|
116
|
+
Uses the Strategy pattern to delegate tool creation to the appropriate
|
117
|
+
loading function based on the tool type.
|
118
|
+
|
69
119
|
Args:
|
70
|
-
tool: Tool configuration
|
120
|
+
tool (Tool): Tool configuration (FunctionTool or McpTool).
|
71
121
|
|
72
122
|
Returns:
|
73
|
-
The created tool or None if creation failed
|
123
|
+
Any | None: The created tool instance or None if creation failed.
|
74
124
|
|
75
125
|
Raises:
|
76
|
-
ValueError: If tool type is not supported or config is invalid
|
126
|
+
ValueError: If tool type is not supported or config is invalid.
|
127
|
+
KeyError: If tool type is not found in STRATEGIES.
|
77
128
|
"""
|
78
129
|
|
79
130
|
return ToolGenerator.STRATEGIES[tool.type](tool)
|