Skip to content

armgit / E2B

Public Imported from GitHub
0

Open-source, secure environment with real-world tools for enterprise-grade agents.

Add agent deployment [WIP]

Tomas Valentad7b3117fc047
diff --git a/api-service/agent/base.py b/api-service/agent/base.py
index c31329ecc..8ffec0efd 100644
--- a/api-service/agent/base.py
+++ b/api-service/agent/base.py
@@ -32,7 +32,7 @@ class RewriteStepsException(Exception):
pass
-class AgentRun:
+class Agent:
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.should_pause = False
@@ -82,14 +82,14 @@ class AgentRun:
def _create_prompt(model_config: ModelConfig, tools: List[BaseTool]):
system_template = "\n\n".join(
[
- AgentRun._get_prompt_part(model_config.prompt, "system", "prefix"),
+ Agent._get_prompt_part(model_config.prompt, "system", "prefix"),
"\n".join([f"{tool.name}: {tool.description}" for tool in tools]),
- AgentRun._get_prompt_part(model_config.prompt, "system", "suffix"),
+ Agent._get_prompt_part(model_config.prompt, "system", "suffix"),
]
)
human_template = "\n\n".join(
[
- AgentRun._get_prompt_part(model_config.prompt, "user", "prefix"),
+ Agent._get_prompt_part(model_config.prompt, "user", "prefix"),
# "{agent_scratchpad}",
]
)
diff --git a/api-service/agent/ws.py b/api-service/agent/ws.py
index 11aad6975..f4ea1a4a8 100644
--- a/api-service/agent/ws.py
+++ b/api-service/agent/ws.py
@@ -1,10 +1,10 @@
from typing import Any, Dict, List
from fastapi import WebSocket
-from agent.base import AgentRun
+from agent.base import Agent
-class WebsocketAgentRun(AgentRun):
+class WebsocketAgentRun(Agent):
jsonrpc_version = "2.0"
def __init__(self, websocket: WebSocket, **kwargs):
diff --git a/api-service/app.py b/api-service/app.py
index 9c5262d2e..093ad9db2 100644
--- a/api-service/app.py
+++ b/api-service/app.py
@@ -1,8 +1,11 @@
from fastapi import FastAPI, WebSocket
from fastapi.middleware.cors import CORSMiddleware
+from pydantic import BaseModel
+from models.base import ModelConfig
from agent.ws import WebsocketAgentRun
+# TODO: Fix proxying - https://fastapi.tiangolo.com/advanced/behind-a-proxy/
app = FastAPI(title="e2b-api-service")
app.add_middleware(
CORSMiddleware,
@@ -17,3 +20,40 @@ app.add_middleware(
async def ws_agent_run(websocket: WebSocket):
run = WebsocketAgentRun(websocket)
await run.handle_agent_run()
+
+
+async def health():
+ return {"status": "ok"}
+
+
+class DeployConfig(BaseModel):
+ pass
+
+class AgentCreateBody(BaseModel):
+ model_config: ModelConfig
+ deploy_config: DeployConfig
+
+
+async def create_agent(body: AgentCreateBody):
+ pass
+
+
+class AgentRunBody(BaseModel):
+ instructions: str
+
+
[email protected]("/agent/{id}/run")
+async def run_agent(id: str, body: AgentRunBody):
+ pass
+
+
[email protected]("/agent/{id}/run/{run_id}/status")
+async def get_agent_run_status(id: str, run_id: str):
+ pass
+
+
[email protected]("/agent/{id}/run/{run_id}/result")
+async def get_agent_run_result(id: str, run_id: str):
+ pass
diff --git a/api-service/deployment/__init__.py b/api-service/deployment/__init__.py
new file mode 100644
index 000000000..e69de29bb
diff --git a/api-service/deployment/adapter.py b/api-service/deployment/adapter.py
new file mode 100644
index 000000000..f86643e22
--- /dev/null
+++ b/api-service/deployment/adapter.py
@@ -0,0 +1,22 @@
+from typing import List
+from abc import ABC, abstractmethod
+
+from agent.base import Agent
+
+
+class DeploymentAdapter(ABC):
+ @abstractmethod
+ async def create_deployed_agent(self, deployment):
+ pass
+
+ @abstractmethod
+ async def remove_deployed_agent(self, deploymen_id: str):
+ pass
+
+ @abstractmethod
+ async def get_deployed_agent(self, deployment_id: str) -> Agent:
+ pass
+
+ @abstractmethod
+ async def get_deployed_agents(self) -> List[Agent]:
+ pass
diff --git a/api-service/deployment/library_deployment.py b/api-service/deployment/library_deployment.py
new file mode 100644
index 000000000..f792ce926
--- /dev/null
+++ b/api-service/deployment/library_deployment.py
@@ -0,0 +1,24 @@
+from typing import Dict
+
+from deployment.adapter import DeploymentAdapter
+from agent.base import Agent
+
+deployments: Dict[str, Agent] = {}
+
+
+class LibraryDeployment(DeploymentAdapter):
+ def __init__(self, deployment):
+ self.deployment = deployment
+
+ async def create_deployed_agent(self, config:):
+
+ pass
+
+ async def remove_deployed_agent(self, deployment_id: str):
+ pass
+
+ async def get_deployed_agent(self, deployment_id: str):
+ pass
+
+ async def get_deployed_agents(self):
+ pass
diff --git a/api-service/openapi.json b/api-service/openapi.json
index dbc8b391b..08bed89d4 100644
--- a/api-service/openapi.json
+++ b/api-service/openapi.json
@@ -5,15 +5,31 @@
"version": "0.1.0"
},
"paths": {
+ "/health": {
+ "get": {
+ "summary": "Health",
+ "operationId": "health_health_get",
+ "responses": {
+ "200": {
+ "description": "Successful Response",
+ "content": {
+ "application/json": {
+ "schema": {}
+ }
+ }
+ }
+ }
+ }
+ },
"/agent": {
"post": {
- "summary": "Generate",
- "operationId": "generate_agent_post",
+ "summary": "Create Agent",
+ "operationId": "create_agent_agent_post",
"requestBody": {
"content": {
"application/json": {
"schema": {
- "$ref": "#/components/schemas/GenerateBody"
+ "$ref": "#/components/schemas/AgentCreateBody"
}
}
},
@@ -40,27 +56,183 @@
}
}
}
+ },
+ "/agent/{id}/run": {
+ "post": {
+ "summary": "Run Agent",
+ "operationId": "run_agent_agent__id__run_post",
+ "parameters": [
+ {
+ "required": true,
+ "schema": {
+ "title": "Id",
+ "type": "string"
+ },
+ "name": "id",
+ "in": "path"
+ }
+ ],
+ "requestBody": {
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/AgentRunBody"
+ }
+ }
+ },
+ "required": true
+ },
+ "responses": {
+ "200": {
+ "description": "Successful Response",
+ "content": {
+ "application/json": {
+ "schema": {}
+ }
+ }
+ },
+ "422": {
+ "description": "Validation Error",
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/HTTPValidationError"
+ }
+ }
+ }
+ }
+ }
+ }
+ },
+ "/agent/{id}/run/{run_id}/status": {
+ "get": {
+ "summary": "Get Agent Run Status",
+ "operationId": "get_agent_run_status_agent__id__run__run_id__status_get",
+ "parameters": [
+ {
+ "required": true,
+ "schema": {
+ "title": "Id",
+ "type": "string"
+ },
+ "name": "id",
+ "in": "path"
+ },
+ {
+ "required": true,
+ "schema": {
+ "title": "Run Id",
+ "type": "string"
+ },
+ "name": "run_id",
+ "in": "path"
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "Successful Response",
+ "content": {
+ "application/json": {
+ "schema": {}
+ }
+ }
+ },
+ "422": {
+ "description": "Validation Error",
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/HTTPValidationError"
+ }
+ }
+ }
+ }
+ }
+ }
+ },
+ "/agent/{id}/run/{run_id}/result": {
+ "get": {
+ "summary": "Get Agent Run Result",
+ "operationId": "get_agent_run_result_agent__id__run__run_id__result_get",
+ "parameters": [
+ {
+ "required": true,
+ "schema": {
+ "title": "Id",
+ "type": "string"
+ },
+ "name": "id",
+ "in": "path"
+ },
+ {
+ "required": true,
+ "schema": {
+ "title": "Run Id",
+ "type": "string"
+ },
+ "name": "run_id",
+ "in": "path"
+ }
+ ],
+ "responses": {
+ "200": {
+ "description": "Successful Response",
+ "content": {
+ "application/json": {
+ "schema": {}
+ }
+ }
+ },
+ "422": {
+ "description": "Validation Error",
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/HTTPValidationError"
+ }
+ }
+ }
+ }
+ }
+ }
}
},
"components": {
"schemas": {
- "GenerateBody": {
- "title": "GenerateBody",
+ "AgentCreateBody": {
+ "title": "AgentCreateBody",
"required": [
- "project_id",
- "model_config"
+ "model_config",
+ "deploy_config"
],
"type": "object",
"properties": {
- "project_id": {
- "title": "Project Id",
- "type": "string"
- },
"model_config": {
"$ref": "#/components/schemas/ModelConfig"
+ },
+ "deploy_config": {
+ "$ref": "#/components/schemas/DeployConfig"
}
}
},
+ "AgentRunBody": {
+ "title": "AgentRunBody",
+ "required": [
+ "instructions"
+ ],
+ "type": "object",
+ "properties": {
+ "instructions": {
+ "title": "Instructions",
+ "type": "string"
+ }
+ }
+ },
+ "DeployConfig": {
+ "title": "DeployConfig",
+ "type": "object",
+ "properties": {}
+ },
"HTTPValidationError": {
"title": "HTTPValidationError",
"type": "object",
diff --git a/pages/api/service/[...all].ts b/pages/api/service/[...all].ts
index 22dd8e2ac..ee6d8d5b6 100644
--- a/pages/api/service/[...all].ts
+++ b/pages/api/service/[...all].ts
@@ -23,7 +23,7 @@ const proxy = createProxyMiddleware<NextApiRequest, NextApiResponse>({
ws: true,
secure: !isSecure,
changeOrigin: true,
- pathRewrite: { [`^${pathPrefix}`]: '' }, // remove prefix
+ // pathRewrite: { [`^${pathPrefix}`]: '' }, // remove prefix
})
export default function handler(req: NextApiRequest, res: NextApiResponse) {
diff --git a/utils/capitalize.ts b/utils/capitalize.ts
index 7519095d0..a3415bd00 100644
--- a/utils/capitalize.ts
+++ b/utils/capitalize.ts
@@ -1,3 +1,3 @@
export function capitalize(str: string) {
- return str.charAt(0).toUpperCase() + str.slice(1);
+ return str.charAt(0).toUpperCase() + str.slice(1)
}