ソースを参照

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

* adding functinality to get agents from backend server

* dynamic selection of agents in backend

* adding the function listAgents

* Update opendevin/server/listen.py

* Update opendevin/agent.py

---------

Co-authored-by: Robert Brennan <accounts@rbren.io>
Manal Arora 1 年間 前
コミット
87d56d961f

+ 10 - 3
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>
   );

+ 7 - 2
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 } };

+ 10 - 0
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())
+        

+ 9 - 1
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
+
+@app.get("/litellm-agents")
+async def get_litellm_agents():
+    """
+    Get all agents supported by LiteLLM.
+    """
+    return Agent.listAgents()