Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an endpoint for service metadata and use it to configure the app #116

Merged
merged 9 commits into from
Dec 10, 2024
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,21 @@ docker compose watch
1. **Multiple Agent Support**: Run multiple agents in the service and call by URL path
1. **Asynchronous Design**: Utilizes async/await for efficient handling of concurrent requests.
1. **Feedback Mechanism**: Includes a star-based feedback system integrated with LangSmith.
1. **Dynamic Metadata**: `/info` endpoint provides dynamically configured metadata about the service and available agents and models.
1. **Docker Support**: Includes Dockerfiles and a docker compose file for easy development and deployment.
1. **Testing**: Includes robust unit and integration tests for the full repo.

### Key Files

The repository is structured as follows:

- `src/agents/research_assistant.py`: Defines the main LangGraph agent
- `src/agents/llama_guard.py`: Defines the LlamaGuard content moderation
- `src/agents/models.py`: Configures available models based on ENV
- `src/agents/agents.py`: Mapping of all agents provided by the service
- `src/schema/schema.py`: Defines the protocol schema
- `src/agents/`: Defines several agents with different capabilities
- `src/schema/`: Defines the protocol schema
- `src/core/`: Core modules including LLM definition and settings
- `src/service/service.py`: FastAPI service to serve the agents
- `src/client/client.py`: Client to interact with the agent service
- `src/streamlit_app.py`: Streamlit app providing a chat interface
- `tests/`: Unit and integration tests

## Why LangGraph?

Expand Down Expand Up @@ -213,7 +214,7 @@ Contributions are welcome! Please feel free to submit a Pull Request.
- [x] Add more sophisticated tools for the research assistant
- [x] Increase test coverage and add CI pipeline
- [x] Add support for multiple agents running on the same service, including non-chat agent
- [ ] Deployment instructions and configuration for cloud providers
- [x] Service metadata endpoint `/info` and dynamic app configuration
- [ ] More ideas? File an issue or create a discussion!

## License
Expand Down
4 changes: 2 additions & 2 deletions src/agents/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from agents.agents import DEFAULT_AGENT, agents
from agents.agents import DEFAULT_AGENT, get_agent, get_all_agent_info

__all__ = ["agents", "DEFAULT_AGENT"]
__all__ = ["get_agent", "get_all_agent_info", "DEFAULT_AGENT"]
29 changes: 25 additions & 4 deletions src/agents/agents.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,35 @@
from dataclasses import dataclass

from langgraph.graph.state import CompiledStateGraph

from agents.bg_task_agent.bg_task_agent import bg_task_agent
from agents.chatbot import chatbot
from agents.research_assistant import research_assistant
from schema import AgentInfo

DEFAULT_AGENT = "research-assistant"


agents: dict[str, CompiledStateGraph] = {
"chatbot": chatbot,
"research-assistant": research_assistant,
"bg-task-agent": bg_task_agent,
@dataclass
class Agent:
description: str
graph: CompiledStateGraph


agents: dict[str, Agent] = {
"chatbot": Agent(description="A simple chatbot.", graph=chatbot),
"research-assistant": Agent(
description="A research assistant with web search and calculator.", graph=research_assistant
),
"bg-task-agent": Agent(description="A background task agent.", graph=bg_task_agent),
}


def get_agent(agent_id: str) -> CompiledStateGraph:
return agents[agent_id].graph


def get_all_agent_info() -> list[AgentInfo]:
return [
AgentInfo(key=agent_id, description=agent.description) for agent_id, agent in agents.items()
]
6 changes: 5 additions & 1 deletion src/agents/research_assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import Literal

from langchain_community.tools import DuckDuckGoSearchResults, OpenWeatherMapQueryRun
from langchain_community.utilities import OpenWeatherMapAPIWrapper
from langchain_core.language_models.chat_models import BaseChatModel
from langchain_core.messages import AIMessage, SystemMessage
from langchain_core.runnables import RunnableConfig, RunnableLambda, RunnableSerializable
Expand Down Expand Up @@ -31,7 +32,10 @@
# Add weather tool if API key is set
# Register for an API key at https://openweathermap.org/api/
if settings.OPENWEATHERMAP_API_KEY:
tools.append(OpenWeatherMapQueryRun(name="Weather"))
wrapper = OpenWeatherMapAPIWrapper(

Check warning on line 35 in src/agents/research_assistant.py

View check run for this annotation

Codecov / codecov/patch

src/agents/research_assistant.py#L35

Added line #L35 was not covered by tests
openweathermap_api_key=settings.OPENWEATHERMAP_API_KEY.get_secret_value()
)
tools.append(OpenWeatherMapQueryRun(name="Weather", api_wrapper=wrapper))

Check warning on line 38 in src/agents/research_assistant.py

View check run for this annotation

Codecov / codecov/patch

src/agents/research_assistant.py#L38

Added line #L38 was not covered by tests

current_date = datetime.now().strftime("%B %d, %Y")
instructions = f"""
Expand Down
4 changes: 2 additions & 2 deletions src/client/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from client.client import AgentClient
from client.client import AgentClient, AgentClientError

__all__ = ["AgentClient"]
__all__ = ["AgentClient", "AgentClientError"]
Loading
Loading