ayn 0.0.2__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.
ayn/__init__.py ADDED
@@ -0,0 +1,122 @@
1
+ """ayn - Agents You Need
2
+
3
+ A meta-framework for discovering, installing, and integrating reusable AI agents.
4
+ Acts as the 'pip + Docker Hub + Postman' for AI agents.
5
+
6
+ Core Features:
7
+ 1. Search & Discovery: Find agents across GitHub, HuggingFace, awesome lists
8
+ 2. Standard Controller Interface: Parametrizable agent controllers with action methods
9
+ 3. HTTP/REST Export: FastAPI and LangServe wrappers
10
+ 4. MCP Support: Model Context Protocol server integration
11
+ 5. Custom Actions: ChatGPT and Claude action generation
12
+
13
+ Architecture:
14
+ - Search layer: Unified registry across multiple sources
15
+ - Controller protocol: Standard interface for invoking agents
16
+ - Export layer: HTTP/REST service generation
17
+ - MCP layer: Tools, resources, and prompts
18
+ - Actions: OpenAPI specs for ChatGPT/Claude
19
+
20
+ Example:
21
+ >>> from ayn import AgentRegistry, BaseAgentController
22
+ >>> registry = AgentRegistry() # doctest: +SKIP
23
+ >>> results = registry.search('data preparation agents') # doctest: +SKIP
24
+ >>> agent = BaseAgentController.from_metadata(results[0]) # doctest: +SKIP
25
+ >>> result = agent.invoke(input_data) # doctest: +SKIP
26
+ """
27
+
28
+ from __future__ import annotations
29
+
30
+ __version__ = "0.0.1"
31
+
32
+ # Core models and config
33
+ from .core import (
34
+ AgentFramework,
35
+ AgentModality,
36
+ AgentMetadata,
37
+ ControllerConfig,
38
+ )
39
+
40
+ # Registry and search
41
+ from .registry import (
42
+ AgentSearcher,
43
+ GitHubAgentSearcher,
44
+ HuggingFaceAgentSearcher,
45
+ AwesomeListSearcher,
46
+ AgentRegistry,
47
+ )
48
+
49
+ # Controllers
50
+ from .controllers import (
51
+ AgentController,
52
+ BaseAgentController,
53
+ GenericController,
54
+ CrewAIController,
55
+ LangChainController,
56
+ AutoGenController,
57
+ )
58
+
59
+ # Export
60
+ from .export import (
61
+ export_as_fastapi,
62
+ export_as_langserve,
63
+ )
64
+
65
+ # MCP
66
+ from .mcp import (
67
+ MCPTool,
68
+ MCPResource,
69
+ MCPPrompt,
70
+ MCPServer,
71
+ controller_to_mcp_server,
72
+ )
73
+
74
+ # Actions
75
+ from .actions import (
76
+ generate_chatgpt_action,
77
+ generate_claude_mcp_config,
78
+ )
79
+
80
+ # Utilities
81
+ from .utils import (
82
+ create_agent_from_registry,
83
+ export_agent_full_stack,
84
+ )
85
+
86
+ __all__ = [
87
+ # Version
88
+ "__version__",
89
+ # Data models
90
+ "AgentFramework",
91
+ "AgentModality",
92
+ "AgentMetadata",
93
+ "ControllerConfig",
94
+ # Search
95
+ "AgentSearcher",
96
+ "GitHubAgentSearcher",
97
+ "HuggingFaceAgentSearcher",
98
+ "AwesomeListSearcher",
99
+ "AgentRegistry",
100
+ # Controller
101
+ "AgentController",
102
+ "BaseAgentController",
103
+ "GenericController",
104
+ "CrewAIController",
105
+ "LangChainController",
106
+ "AutoGenController",
107
+ # Export
108
+ "export_as_fastapi",
109
+ "export_as_langserve",
110
+ # MCP
111
+ "MCPTool",
112
+ "MCPResource",
113
+ "MCPPrompt",
114
+ "MCPServer",
115
+ "controller_to_mcp_server",
116
+ # Actions
117
+ "generate_chatgpt_action",
118
+ "generate_claude_mcp_config",
119
+ # Convenience
120
+ "create_agent_from_registry",
121
+ "export_agent_full_stack",
122
+ ]
@@ -0,0 +1,9 @@
1
+ """Custom actions for ChatGPT and Claude."""
2
+
3
+ from .chatgpt import generate_chatgpt_action
4
+ from .claude import generate_claude_mcp_config
5
+
6
+ __all__ = [
7
+ "generate_chatgpt_action",
8
+ "generate_claude_mcp_config",
9
+ ]
ayn/actions/chatgpt.py ADDED
@@ -0,0 +1,101 @@
1
+ """ChatGPT custom action generation."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from ..controllers.base import AgentController
6
+ from ..core.models import AgentMetadata
7
+
8
+
9
+ def _generate_openapi_spec(
10
+ controller: AgentController, metadata: AgentMetadata
11
+ ) -> dict:
12
+ """Generate OpenAPI spec for agent
13
+
14
+ Uses oa package if available for better spec generation.
15
+
16
+ Args:
17
+ controller: Agent controller
18
+ metadata: Agent metadata
19
+
20
+ Returns:
21
+ OpenAPI 3.0 specification dict
22
+ """
23
+ spec = {
24
+ "openapi": "3.0.0",
25
+ "info": {
26
+ "title": metadata.name,
27
+ "description": metadata.description,
28
+ "version": metadata.version,
29
+ },
30
+ "servers": [{"url": "https://api.example.com"}],
31
+ "paths": {
32
+ "/invoke": {
33
+ "post": {
34
+ "summary": "Invoke the agent",
35
+ "operationId": "invokeAgent",
36
+ "requestBody": {
37
+ "required": True,
38
+ "content": {
39
+ "application/json": {
40
+ "schema": {
41
+ "type": "object",
42
+ "properties": {
43
+ "input_data": {"type": "object"},
44
+ "kwargs": {"type": "object"},
45
+ },
46
+ "required": ["input_data"],
47
+ }
48
+ }
49
+ },
50
+ },
51
+ "responses": {
52
+ "200": {
53
+ "description": "Successful response",
54
+ "content": {
55
+ "application/json": {
56
+ "schema": {
57
+ "type": "object",
58
+ "properties": {"result": {"type": "object"}},
59
+ }
60
+ }
61
+ },
62
+ }
63
+ },
64
+ }
65
+ }
66
+ },
67
+ }
68
+
69
+ return spec
70
+
71
+
72
+ def generate_chatgpt_action(
73
+ controller: AgentController, metadata: AgentMetadata, api_url: str
74
+ ) -> dict:
75
+ """Generate ChatGPT custom action configuration
76
+
77
+ Args:
78
+ controller: Agent controller
79
+ metadata: Agent metadata
80
+ api_url: Base URL for the API
81
+
82
+ Returns:
83
+ ChatGPT action configuration
84
+
85
+ Example:
86
+ >>> from ayn.controllers import GenericController
87
+ >>> from ayn.core import AgentMetadata, AgentFramework, ControllerConfig
88
+ >>> meta = AgentMetadata(name="test", description="test", framework=AgentFramework.CUSTOM)
89
+ >>> controller = GenericController(meta, ControllerConfig())
90
+ >>> action = generate_chatgpt_action(controller, meta, "https://api.example.com")
91
+ >>> action['schema']['info']['title']
92
+ 'test'
93
+ """
94
+ openapi_spec = _generate_openapi_spec(controller, metadata)
95
+ openapi_spec["servers"][0]["url"] = api_url
96
+
97
+ return {
98
+ "schema": openapi_spec,
99
+ "authentication": {"type": "none"}, # Configure as needed
100
+ "instructions": f"Use this action to {metadata.description.lower()}",
101
+ }
ayn/actions/claude.py ADDED
@@ -0,0 +1,48 @@
1
+ """Claude Desktop MCP configuration generation."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from ..mcp.server import MCPServer
6
+
7
+
8
+ def generate_claude_mcp_config(
9
+ mcp_server: MCPServer, server_url: str, transport: str = "sse"
10
+ ) -> dict:
11
+ """Generate Claude Desktop MCP configuration
12
+
13
+ Args:
14
+ mcp_server: MCP server instance
15
+ server_url: URL where MCP server is hosted
16
+ transport: Transport type (sse, stdio)
17
+
18
+ Returns:
19
+ Claude Desktop MCP config
20
+
21
+ Example:
22
+ >>> from ayn.mcp import MCPServer
23
+ >>> server = MCPServer("test")
24
+ >>> config = generate_claude_mcp_config(server, "http://localhost:8000")
25
+ >>> config['mcpServers']['test']['url']
26
+ 'http://localhost:8000/sse'
27
+ """
28
+ if transport == "sse":
29
+ return {
30
+ "mcpServers": {
31
+ mcp_server.name: {
32
+ "url": f"{server_url}/sse",
33
+ "transport": {"type": "sse"},
34
+ }
35
+ }
36
+ }
37
+ elif transport == "stdio":
38
+ return {
39
+ "mcpServers": {
40
+ mcp_server.name: {
41
+ "command": "python",
42
+ "args": ["-m", "mcp_server"],
43
+ "transport": {"type": "stdio"},
44
+ }
45
+ }
46
+ }
47
+ else:
48
+ raise ValueError(f"Unsupported transport: {transport}")
@@ -0,0 +1,14 @@
1
+ """Agent controllers for invoking agents."""
2
+
3
+ from .base import AgentController, BaseAgentController
4
+ from .generic import GenericController
5
+ from .framework import CrewAIController, LangChainController, AutoGenController
6
+
7
+ __all__ = [
8
+ "AgentController",
9
+ "BaseAgentController",
10
+ "GenericController",
11
+ "CrewAIController",
12
+ "LangChainController",
13
+ "AutoGenController",
14
+ ]
@@ -0,0 +1,97 @@
1
+ """Base controller protocol and abstract class."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from abc import ABC, abstractmethod
6
+ from typing import Any, Iterable, Optional, Protocol
7
+
8
+ from ..core.config import ControllerConfig
9
+ from ..core.models import AgentMetadata, AgentFramework
10
+
11
+
12
+ class AgentController(Protocol):
13
+ """Standard protocol for agent controllers
14
+
15
+ Controllers provide a uniform interface for invoking agents regardless
16
+ of their underlying framework.
17
+
18
+ Example:
19
+ >>> class MyController:
20
+ ... def __init__(self, config):
21
+ ... self.config = config
22
+ ... def invoke(self, input_data, **kwargs):
23
+ ... return f"Processed: {input_data}"
24
+ >>> controller = MyController({'model': 'gpt-4'})
25
+ >>> controller.invoke('test')
26
+ 'Processed: test'
27
+ """
28
+
29
+ def invoke(self, input_data: Any, **kwargs) -> Any:
30
+ """Invoke the agent synchronously
31
+
32
+ Args:
33
+ input_data: Input data for the agent
34
+ **kwargs: Additional parameters
35
+
36
+ Returns:
37
+ Agent output
38
+ """
39
+ ...
40
+
41
+ async def ainvoke(self, input_data: Any, **kwargs) -> Any:
42
+ """Invoke the agent asynchronously"""
43
+ ...
44
+
45
+ def stream(self, input_data: Any, **kwargs) -> Iterable[Any]:
46
+ """Stream agent outputs"""
47
+ ...
48
+
49
+
50
+ class BaseAgentController(ABC):
51
+ """Base class for agent controllers
52
+
53
+ Provides common functionality and enforces the controller protocol.
54
+
55
+ Example:
56
+ >>> class SimpleController(BaseAgentController):
57
+ ... def invoke(self, input_data, **kwargs):
58
+ ... return f"Result: {input_data}"
59
+ >>> controller = SimpleController(ControllerConfig())
60
+ >>> controller.invoke('test')
61
+ 'Result: test'
62
+ """
63
+
64
+ def __init__(self, config: ControllerConfig):
65
+ self.config = config
66
+
67
+ @abstractmethod
68
+ def invoke(self, input_data: Any, **kwargs) -> Any:
69
+ """Invoke the agent - must be implemented by subclasses"""
70
+ pass
71
+
72
+ async def ainvoke(self, input_data: Any, **kwargs) -> Any:
73
+ """Default async implementation wraps synchronous invoke"""
74
+ return self.invoke(input_data, **kwargs)
75
+
76
+ def stream(self, input_data: Any, **kwargs) -> Iterable[Any]:
77
+ """Default streaming yields single result"""
78
+ yield self.invoke(input_data, **kwargs)
79
+
80
+ @classmethod
81
+ def from_metadata(
82
+ cls, metadata: AgentMetadata, config: Optional[ControllerConfig] = None
83
+ ) -> BaseAgentController:
84
+ """Factory method to create controller from metadata"""
85
+ from .generic import GenericController
86
+ from .framework import CrewAIController, LangChainController, AutoGenController
87
+
88
+ config = config or ControllerConfig()
89
+ # Route to appropriate framework-specific controller
90
+ if metadata.framework == AgentFramework.CREWAI:
91
+ return CrewAIController(metadata, config)
92
+ elif metadata.framework == AgentFramework.LANGCHAIN:
93
+ return LangChainController(metadata, config)
94
+ elif metadata.framework == AgentFramework.AUTOGEN:
95
+ return AutoGenController(metadata, config)
96
+ else:
97
+ return GenericController(metadata, config)
@@ -0,0 +1,35 @@
1
+ """Framework-specific controller implementations."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from .generic import GenericController
6
+
7
+
8
+ class CrewAIController(GenericController):
9
+ """Controller for CrewAI agents
10
+
11
+ TODO: Implement full CrewAI integration
12
+ See AYN_IMPLEMENTATION_ROADMAP.md for details
13
+ """
14
+
15
+ pass
16
+
17
+
18
+ class LangChainController(GenericController):
19
+ """Controller for LangChain agents
20
+
21
+ TODO: Implement full LangChain integration
22
+ See AYN_IMPLEMENTATION_ROADMAP.md for details
23
+ """
24
+
25
+ pass
26
+
27
+
28
+ class AutoGenController(GenericController):
29
+ """Controller for AutoGen agents
30
+
31
+ TODO: Implement full AutoGen integration
32
+ See AYN_IMPLEMENTATION_ROADMAP.md for details
33
+ """
34
+
35
+ pass
@@ -0,0 +1,28 @@
1
+ """Generic controller for custom agents."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Any
6
+
7
+ from ..core.config import ControllerConfig
8
+ from ..core.models import AgentMetadata
9
+ from .base import BaseAgentController
10
+
11
+
12
+ class GenericController(BaseAgentController):
13
+ """Generic controller for custom agents
14
+
15
+ Example:
16
+ >>> from ayn.core import AgentMetadata, AgentFramework, ControllerConfig
17
+ >>> meta = AgentMetadata(name="test", description="test", framework=AgentFramework.CUSTOM)
18
+ >>> controller = GenericController(meta, ControllerConfig())
19
+ >>> result = controller.invoke({'input': 'test'})
20
+ """
21
+
22
+ def __init__(self, metadata: AgentMetadata, config: ControllerConfig):
23
+ super().__init__(config)
24
+ self.metadata = metadata
25
+
26
+ def invoke(self, input_data: Any, **kwargs) -> Any:
27
+ """Generic invoke - subclasses override for specific behavior"""
28
+ return {"status": "success", "input": input_data, "agent": self.metadata.name}
ayn/core/__init__.py ADDED
@@ -0,0 +1,11 @@
1
+ """Core data models and configuration for AYN."""
2
+
3
+ from .models import AgentFramework, AgentModality, AgentMetadata
4
+ from .config import ControllerConfig
5
+
6
+ __all__ = [
7
+ "AgentFramework",
8
+ "AgentModality",
9
+ "AgentMetadata",
10
+ "ControllerConfig",
11
+ ]
ayn/core/config.py ADDED
@@ -0,0 +1,33 @@
1
+ """Configuration for agent controllers."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from dataclasses import dataclass, field, asdict
6
+ from typing import Optional
7
+
8
+
9
+ @dataclass
10
+ class ControllerConfig:
11
+ """Configuration for agent controllers
12
+
13
+ Example:
14
+ >>> config = ControllerConfig(
15
+ ... model="gpt-4",
16
+ ... temperature=0.7,
17
+ ... max_tokens=1000
18
+ ... )
19
+ >>> config.model
20
+ 'gpt-4'
21
+ """
22
+
23
+ model: str = "gpt-4"
24
+ temperature: float = 0.7
25
+ max_tokens: int = 1000
26
+ timeout: int = 60
27
+ retry_count: int = 3
28
+ api_key: Optional[str] = None
29
+ additional_params: dict = field(default_factory=dict)
30
+
31
+ def to_dict(self) -> dict:
32
+ """Convert to dictionary"""
33
+ return asdict(self)
ayn/core/models.py ADDED
@@ -0,0 +1,80 @@
1
+ """Core data models for agents."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from dataclasses import dataclass, field, asdict
6
+ from enum import Enum
7
+ from typing import List
8
+
9
+
10
+ class AgentFramework(Enum):
11
+ """Supported agent frameworks"""
12
+
13
+ CREWAI = "crewai"
14
+ LANGCHAIN = "langchain"
15
+ LANGGRAPH = "langgraph"
16
+ AUTOGEN = "autogen"
17
+ SWARMS = "swarms"
18
+ SMOLAGENTS = "smolagents"
19
+ SUPERAGI = "superagi"
20
+ CUSTOM = "custom"
21
+
22
+
23
+ class AgentModality(Enum):
24
+ """Agent modalities"""
25
+
26
+ TEXT = "text"
27
+ VISION = "vision"
28
+ AUDIO = "audio"
29
+ MULTIMODAL = "multimodal"
30
+
31
+
32
+ @dataclass
33
+ class AgentMetadata:
34
+ """Metadata for an agent
35
+
36
+ Example:
37
+ >>> meta = AgentMetadata(
38
+ ... name="data-prep-agent",
39
+ ... description="Prepares data for visualization",
40
+ ... framework=AgentFramework.CREWAI
41
+ ... )
42
+ >>> meta.name
43
+ 'data-prep-agent'
44
+ """
45
+
46
+ name: str
47
+ description: str
48
+ framework: AgentFramework
49
+ source: str = "" # GitHub URL, HF model ID, etc.
50
+ tags: List[str] = field(default_factory=list)
51
+ modality: AgentModality = AgentModality.TEXT
52
+ version: str = "0.1.0"
53
+ author: str = ""
54
+ license: str = ""
55
+ dependencies: List[str] = field(default_factory=list)
56
+ capabilities: List[str] = field(default_factory=list)
57
+
58
+ def to_dict(self) -> dict:
59
+ """Convert to dictionary
60
+
61
+ Example:
62
+ >>> meta = AgentMetadata(name="test", description="test agent", framework=AgentFramework.CREWAI)
63
+ >>> d = meta.to_dict()
64
+ >>> d['name']
65
+ 'test'
66
+ """
67
+ result = asdict(self)
68
+ result["framework"] = self.framework.value
69
+ result["modality"] = self.modality.value
70
+ return result
71
+
72
+ @classmethod
73
+ def from_dict(cls, data: dict) -> AgentMetadata:
74
+ """Create from dictionary"""
75
+ data = data.copy()
76
+ if isinstance(data.get("framework"), str):
77
+ data["framework"] = AgentFramework(data["framework"])
78
+ if isinstance(data.get("modality"), str):
79
+ data["modality"] = AgentModality(data["modality"])
80
+ return cls(**data)
ayn/export/__init__.py ADDED
@@ -0,0 +1,9 @@
1
+ """Export agents as HTTP/REST services."""
2
+
3
+ from .fastapi_export import export_as_fastapi
4
+ from .langserve_export import export_as_langserve
5
+
6
+ __all__ = [
7
+ "export_as_fastapi",
8
+ "export_as_langserve",
9
+ ]