Skip to content

πŸ™Œ OpenHands: AI-Driven Development

feat(frontend): adding functinality to get agents from backend server (#406)

Manal Arora87d56d961ffb
diff --git a/frontend/src/components/BannerSettings.tsx b/frontend/src/components/BannerSettings.tsx
index 065b9f14f7..98eb7a049b 100644
--- a/frontend/src/components/BannerSettings.tsx
+++ b/frontend/src/components/BannerSettings.tsx
@@ -1,9 +1,10 @@
import React, { ChangeEvent, useEffect, useState } from "react";
import {
- AGENTS,
+ INITIAL_AGENTS,
INITIAL_MODELS,
changeAgent,
changeModel,
+ fetchAgents,
fetchModels,
} from "../services/settingsService";
import "./css/BannerSettings.css";
@@ -31,6 +32,12 @@ function ModelSelect(): JSX.Element {
}
function AgentSelect(): JSX.Element {
+ const [agents, setAgents] = useState<string[]>(INITIAL_AGENTS);
+ useEffect(() => {
+ fetchAgents().then((fetchedAgents) => {
+ setAgents(fetchedAgents);
+ });
+ }, []);
return (
<select
onChange={(e: ChangeEvent<HTMLSelectElement>) =>
@@ -38,8 +45,8 @@ function AgentSelect(): JSX.Element {
}
className="select max-w-xs bg-base-300 xl:w-full w-1/3"
>
- {AGENTS.map((agent) => (
- <option>{agent}</option>
+ {agents.map((agent) => (
+ <option key={agent}>{agent}</option>
))}
</select>
);
diff --git a/frontend/src/services/settingsService.ts b/frontend/src/services/settingsService.ts
index db540ffe88..bac60bc34a 100644
--- a/frontend/src/services/settingsService.ts
+++ b/frontend/src/services/settingsService.ts
@@ -9,6 +9,11 @@ export async function fetchModels() {
return response.json();
}
+export async function fetchAgents() {
+ const response = await fetch(`${VITE_URL}/litellm-agents`);
+ return response.json();
+}
+
export const INITIAL_MODELS = [
"gpt-3.5-turbo-1106",
"gpt-4-0125-preview",
@@ -19,9 +24,9 @@ export const INITIAL_MODELS = [
export type Model = (typeof INITIAL_MODELS)[number];
-export const AGENTS = ["LangchainsAgent", "CodeActAgent"];
+export const INITIAL_AGENTS = ["LangchainsAgent", "CodeActAgent"];
-export type Agent = (typeof AGENTS)[number];
+export type Agent = (typeof INITIAL_AGENTS)[number];
function changeSetting(setting: string, value: string): void {
const event = { action: "initialize", args: { [setting]: value } };
diff --git a/opendevin/agent.py b/opendevin/agent.py
index efaf239bf2..7928635856 100644
--- a/opendevin/agent.py
+++ b/opendevin/agent.py
@@ -89,3 +89,13 @@ class Agent(ABC):
if name not in cls._registry:
raise ValueError(f"No agent class registered under '{name}'.")
return cls._registry[name]
+
+ @classmethod
+ def listAgents(cls) -> list[str]:
+ """
+ Retrieves the list of all agent names from the registry.
+ """
+ if not bool(cls._registry):
+ raise ValueError("No agent class registered.")
+ return list(cls._registry.keys())
+
\ No newline at end of file
diff --git a/opendevin/server/listen.py b/opendevin/server/listen.py
index 96dfa7a30b..2287019840 100644
--- a/opendevin/server/listen.py
+++ b/opendevin/server/listen.py
@@ -2,7 +2,8 @@ from opendevin.server.session import Session
from fastapi import FastAPI, WebSocket
from fastapi.middleware.cors import CORSMiddleware
import agenthub # noqa F401 (we import this to get the agents registered)
-import litellm
+import litellm
+from opendevin.agent import Agent
app = FastAPI()
@@ -28,3 +29,10 @@ async def get_litellm_models():
Get all models supported by LiteLLM.
"""
return litellm.model_list
+
[email protected]("/litellm-agents")
+async def get_litellm_agents():
+ """
+ Get all agents supported by LiteLLM.
+ """
+ return Agent.listAgents()