-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into nerdai/message-queue
- Loading branch information
Showing
10 changed files
with
272 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,6 @@ on: | |
|
||
env: | ||
POETRY_VERSION: "1.6.1" | ||
LLAMA_CLOUD_API_KEY: ${{ secrets.LLAMA_CLOUD_API_KEY }} | ||
|
||
jobs: | ||
test: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1 @@ | ||
.pants.d/ | ||
dist/ | ||
migration_scripts/ | ||
venv/ | ||
.idea | ||
.venv/ | ||
.ipynb_checkpoints | ||
.__pycache__ | ||
__pycache__ | ||
dev_notebooks/ | ||
llamaindex_registry.txt | ||
packages_to_bump_deduped.txt | ||
.env | ||
credentials.json | ||
token.json | ||
.python-version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from agentfile.agent_server.base import BaseAgentServer | ||
from agentfile.agent_server.fastapi_agent import FastAPIAgentServer | ||
from agentfile.agent_server.types import ( | ||
_Task, | ||
_TaskSate, | ||
_TaskStep, | ||
_TaskStepOutput, | ||
_ChatMessage, | ||
AgentRole, | ||
) | ||
|
||
__all__ = [ | ||
"BaseAgentServer", | ||
"FastAPIAgentServer", | ||
"_Task", | ||
"_TaskSate", | ||
"_TaskStep", | ||
"_TaskStepOutput", | ||
"_ChatMessage", | ||
"AgentRole", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
from abc import ABC, abstractmethod | ||
from typing import Dict, List | ||
|
||
from agentfile.agent_server.types import _Task, _TaskSate, _TaskStep, _TaskStepOutput | ||
|
||
|
||
class BaseAgentServer(ABC): | ||
@abstractmethod | ||
def launch(self) -> None: | ||
"""Launch the agent server.""" | ||
... | ||
|
||
@abstractmethod | ||
async def home(self) -> Dict[str, str]: | ||
"""Get the home page of the server, usually containing status info.""" | ||
... | ||
|
||
@abstractmethod | ||
async def create_task(self, input: str) -> _Task: | ||
"""Create a new task.""" | ||
... | ||
|
||
@abstractmethod | ||
async def get_tasks(self) -> List[_Task]: | ||
"""Get a list of all tasks.""" | ||
... | ||
|
||
@abstractmethod | ||
async def get_task_state(self, task_id: str) -> _TaskSate: | ||
"""Get a specific state of a task.""" | ||
... | ||
|
||
@abstractmethod | ||
async def get_completed_tasks(self) -> List[_Task]: | ||
"""Get a list of all completed tasks.""" | ||
... | ||
|
||
@abstractmethod | ||
async def get_task_output(self, task_id: str) -> _TaskStepOutput: | ||
"""Get the output of a task.""" | ||
... | ||
|
||
@abstractmethod | ||
async def get_task_steps(self, task_id: str) -> List[_TaskStep]: | ||
"""Get the steps of a task.""" | ||
... | ||
|
||
@abstractmethod | ||
async def get_completed_steps(self, task_id: str) -> List[_TaskStepOutput]: | ||
"""Get the completed steps of a task.""" | ||
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
""" | ||
What does the processing loop for the control plane look like? | ||
- check message queue | ||
- handle incoming new tasks | ||
- handle incoming general chats | ||
- handle agents returning a completed task | ||
""" | ||
|
||
from abc import ABC, abstractmethod | ||
|
||
|
||
class BaseControlPlane(ABC): | ||
@abstractmethod | ||
def register_agent(self, agent_id: str, agent_role: str) -> None: | ||
""" | ||
Register an agent with the control plane. | ||
:param agent_id: Unique identifier of the agent. | ||
:param agent_role: Role of the agent. | ||
""" | ||
... | ||
|
||
@abstractmethod | ||
def deregister_agent(self, agent_id: str) -> None: | ||
""" | ||
Deregister an agent from the control plane. | ||
:param agent_id: Unique identifier of the agent. | ||
""" | ||
... | ||
|
||
@abstractmethod | ||
def register_flow(self, flow_id: str, flow_definition: dict) -> None: | ||
""" | ||
Register a flow with the control plane. | ||
:param flow_id: Unique identifier of the flow. | ||
:param flow_definition: Definition of the flow. | ||
""" | ||
... | ||
|
||
@abstractmethod | ||
def deregister_flow(self, flow_id: str) -> None: | ||
""" | ||
Deregister a flow from the control plane. | ||
:param flow_id: Unique identifier of the flow. | ||
""" | ||
... | ||
|
||
@abstractmethod | ||
def handle_new_task(self, task_id: str, task_definition: dict) -> None: | ||
""" | ||
Submit a task to the control plane. | ||
:param task_id: Unique identifier of the task. | ||
:param task_definition: Definition of the task. | ||
""" | ||
... | ||
|
||
@abstractmethod | ||
def send_task_to_agent(self, task_id: str, agent_id: str) -> None: | ||
""" | ||
Send a task to an agent. | ||
:param task_id: Unique identifier of the task. | ||
:param agent_id: Unique identifier of the agent. | ||
""" | ||
... | ||
|
||
@abstractmethod | ||
def handle_agent_completion( | ||
self, task_id: str, agent_id: str, result: dict | ||
) -> None: | ||
""" | ||
Handle the completion of a task by an agent. | ||
:param task_id: Unique identifier of the task. | ||
:param agent_id: Unique identifier of the agent. | ||
:param result: Result of the task. | ||
""" | ||
... | ||
|
||
@abstractmethod | ||
def get_next_agent(self, task_id: str) -> str: | ||
""" | ||
Get the next agent for a task. | ||
:param task_id: Unique identifier of the task. | ||
:return: Unique identifier of the next agent. | ||
""" | ||
... | ||
|
||
@abstractmethod | ||
def get_task_state(self, task_id: str) -> dict: | ||
""" | ||
Get the current state of a task. | ||
:param task_id: Unique identifier of the task. | ||
:return: Current state of the task. | ||
""" | ||
... | ||
|
||
@abstractmethod | ||
def request_user_input(self, task_id: str, message: str) -> None: | ||
""" | ||
Request input from the user for a task. | ||
:param task_id: Unique identifier of the task. | ||
:param message: Message to send to the user. | ||
""" | ||
... | ||
|
||
@abstractmethod | ||
def handle_user_input(self, task_id: str, user_input: str) -> None: | ||
""" | ||
Handle the user input for a task. | ||
:param task_id: Unique identifier of the task. | ||
:param user_input: Input provided by the user. | ||
""" | ||
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from typing import Any, Dict | ||
|
||
from agentfile.control_plane.base import BaseControlPlane | ||
|
||
|
||
class FastAPIControlPlane(BaseControlPlane): | ||
def __init__(self) -> None: | ||
self.agents: Dict[str, Any] = {} | ||
self.flows: Dict[str, Any] = {} | ||
self.tasks: Dict[str, Any] = {} | ||
|
||
def register_agent(self, agent_id: str, agent_role: str) -> None: | ||
self.agents[agent_id] = agent_role | ||
|
||
def deregister_agent(self, agent_id: str) -> None: | ||
del self.agents[agent_id] | ||
|
||
def register_flow(self, flow_id: str, flow_definition: dict) -> None: | ||
self.flows[flow_id] = flow_definition | ||
|
||
def deregister_flow(self, flow_id: str) -> None: | ||
del self.flows[flow_id] | ||
|
||
def handle_new_task(self, task_id: str, task_definition: dict) -> None: | ||
self.tasks[task_id] = task_definition | ||
|
||
def send_task_to_agent(self, task_id: str, agent_id: str) -> None: | ||
pass | ||
|
||
def handle_agent_completion( | ||
self, task_id: str, agent_id: str, result: dict | ||
) -> None: | ||
pass | ||
|
||
def get_next_agent(self, task_id: str) -> str: | ||
return "" | ||
|
||
def get_task_state(self, task_id: str) -> dict: | ||
return self.tasks.get(task_id, None) | ||
|
||
def request_user_input(self, task_id: str, message: str) -> None: | ||
pass | ||
|
||
def handle_user_input(self, task_id: str, user_input: str) -> None: | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters