temp
This commit is contained in:
52
scripts/lib/agents/__init__.py
Normal file
52
scripts/lib/agents/__init__.py
Normal file
@@ -0,0 +1,52 @@
|
||||
import os
|
||||
from typing import Dict, List, Optional
|
||||
from .base import BaseAgent
|
||||
from .antigravity import AntigravityAgent
|
||||
from .hermes import HermesAgent
|
||||
|
||||
_REGISTERED_AGENTS: List[BaseAgent] = [
|
||||
AntigravityAgent(),
|
||||
HermesAgent(),
|
||||
]
|
||||
|
||||
_LOOKUP_MAP: Dict[str, BaseAgent] = {}
|
||||
for agent in _REGISTERED_AGENTS:
|
||||
_LOOKUP_MAP[agent.name.lower()] = agent
|
||||
for alias in agent.aliases:
|
||||
_LOOKUP_MAP[alias.lower()] = agent
|
||||
|
||||
|
||||
def list_agents() -> List[BaseAgent]:
|
||||
"""Return list of all registered agent instances."""
|
||||
return list(_REGISTERED_AGENTS)
|
||||
|
||||
|
||||
def get_agent(name_or_alias: str) -> Optional[BaseAgent]:
|
||||
"""Look up an agent by its primary name or any alias."""
|
||||
return _LOOKUP_MAP.get(name_or_alias.strip().lower())
|
||||
|
||||
|
||||
def get_default_agent() -> BaseAgent:
|
||||
"""
|
||||
Resolve the default agent to use:
|
||||
1. Check TASK_AGENT environment variable.
|
||||
2. Fall back to the first available agent CLI found on PATH.
|
||||
3. If none installed, return the first registered agent (which will report not found on launch).
|
||||
"""
|
||||
env_agent = os.environ.get("TASK_AGENT")
|
||||
if env_agent:
|
||||
matched = get_agent(env_agent)
|
||||
if matched:
|
||||
return matched
|
||||
else:
|
||||
raise ValueError(
|
||||
f"Unknown agent specified in TASK_AGENT='{env_agent}'. "
|
||||
f"Available agents: {', '.join([a.name for a in _REGISTERED_AGENTS])}"
|
||||
)
|
||||
|
||||
# Auto-detect available agent
|
||||
for agent in _REGISTERED_AGENTS:
|
||||
if agent.is_available():
|
||||
return agent
|
||||
|
||||
return _REGISTERED_AGENTS[0]
|
||||
BIN
scripts/lib/agents/__pycache__/__init__.cpython-314.pyc
Normal file
BIN
scripts/lib/agents/__pycache__/__init__.cpython-314.pyc
Normal file
Binary file not shown.
BIN
scripts/lib/agents/__pycache__/antigravity.cpython-314.pyc
Normal file
BIN
scripts/lib/agents/__pycache__/antigravity.cpython-314.pyc
Normal file
Binary file not shown.
BIN
scripts/lib/agents/__pycache__/base.cpython-314.pyc
Normal file
BIN
scripts/lib/agents/__pycache__/base.cpython-314.pyc
Normal file
Binary file not shown.
BIN
scripts/lib/agents/__pycache__/hermes.cpython-314.pyc
Normal file
BIN
scripts/lib/agents/__pycache__/hermes.cpython-314.pyc
Normal file
Binary file not shown.
25
scripts/lib/agents/antigravity.py
Normal file
25
scripts/lib/agents/antigravity.py
Normal file
@@ -0,0 +1,25 @@
|
||||
import os
|
||||
import shutil
|
||||
from typing import List, Optional
|
||||
from .base import BaseAgent
|
||||
|
||||
|
||||
class AntigravityAgent(BaseAgent):
|
||||
"""Adapter for Google Antigravity CLI (agy)."""
|
||||
|
||||
name = "antigravity"
|
||||
aliases = ["agy"]
|
||||
|
||||
def is_available(self) -> bool:
|
||||
return shutil.which("agy") is not None
|
||||
|
||||
def launch(self, prompt: str, extra_args: Optional[List[str]] = None) -> None:
|
||||
bin_path = shutil.which("agy")
|
||||
if not bin_path:
|
||||
raise FileNotFoundError("Antigravity CLI ('agy') is not found on PATH.")
|
||||
|
||||
cmd = [bin_path, "-i", prompt]
|
||||
if extra_args:
|
||||
cmd.extend(extra_args)
|
||||
|
||||
os.execvp(bin_path, cmd)
|
||||
22
scripts/lib/agents/base.py
Normal file
22
scripts/lib/agents/base.py
Normal file
@@ -0,0 +1,22 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import List, Optional
|
||||
|
||||
|
||||
class BaseAgent(ABC):
|
||||
"""Abstract base class for AI CLI agents."""
|
||||
|
||||
name: str = ""
|
||||
aliases: List[str] = []
|
||||
|
||||
@abstractmethod
|
||||
def is_available(self) -> bool:
|
||||
"""Check if the agent CLI binary is installed and reachable in PATH."""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def launch(self, prompt: str, extra_args: Optional[List[str]] = None) -> None:
|
||||
"""Launch the agent interactively with the pre-seeded prompt."""
|
||||
pass
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"<{self.__class__.__name__} name={self.name}>"
|
||||
25
scripts/lib/agents/hermes.py
Normal file
25
scripts/lib/agents/hermes.py
Normal file
@@ -0,0 +1,25 @@
|
||||
import os
|
||||
import shutil
|
||||
from typing import List, Optional
|
||||
from .base import BaseAgent
|
||||
|
||||
|
||||
class HermesAgent(BaseAgent):
|
||||
"""Adapter for Hermes Agent CLI."""
|
||||
|
||||
name = "hermes"
|
||||
aliases = ["hermes-agent"]
|
||||
|
||||
def is_available(self) -> bool:
|
||||
return shutil.which("hermes") is not None
|
||||
|
||||
def launch(self, prompt: str, extra_args: Optional[List[str]] = None) -> None:
|
||||
bin_path = shutil.which("hermes")
|
||||
if not bin_path:
|
||||
raise FileNotFoundError("Hermes CLI ('hermes') is not found on PATH.")
|
||||
|
||||
cmd = [bin_path, "chat", "-q", prompt]
|
||||
if extra_args:
|
||||
cmd.extend(extra_args)
|
||||
|
||||
os.execvp(bin_path, cmd)
|
||||
Reference in New Issue
Block a user