Skip to content

Commit

Permalink
feat(frontend): adding functinality to get agents from backend server (
Browse files Browse the repository at this point in the history
…All-Hands-AI#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>
  • Loading branch information
manalarora and rbren committed Mar 30, 2024
1 parent fd56182 commit 87d56d9
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 6 deletions.
13 changes: 10 additions & 3 deletions frontend/src/components/BannerSettings.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -31,15 +32,21 @@ 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>) =>
changeAgent(e.target.value)
}
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>
);
Expand Down
9 changes: 7 additions & 2 deletions frontend/src/services/settingsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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 } };
Expand Down
10 changes: 10 additions & 0 deletions opendevin/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,13 @@ def get_cls(cls, name: str) -> Type["Agent"]:
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())

10 changes: 9 additions & 1 deletion opendevin/server/listen.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
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()

Expand All @@ -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()

0 comments on commit 87d56d9

Please sign in to comment.