Skip to content

Commit

Permalink
Merge pull request #227 from potpie-ai/custom_agent_routing
Browse files Browse the repository at this point in the history
Route directly to custom agents
  • Loading branch information
dhirenmathur authored Jan 13, 2025
2 parents 050580e + d90779b commit 7aaa12d
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions app/modules/conversations/conversation/conversation_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,17 @@ def __init__(self, db, provider_service):
self.classifier = None
self.agents_service = AgentsService(db)
self.agent_factory = AgentFactory(db, provider_service)
self.available_agents = []

async def initialize(self, user_id: str):
available_agents = await self.agents_service.list_available_agents(
current_user={"user_id": user_id}, list_system_agents=True
)

self.available_agents = available_agents
self.agents = {
agent.id: self.agent_factory.get_agent(agent.id, user_id)
for agent in available_agents
}

self.llm = self.provider_service.get_small_llm(user_id)

self.classifier_prompt = """
Expand Down Expand Up @@ -151,13 +151,19 @@ async def classifier_node(self, state: State) -> Command:
"""Classifies the query and routes to appropriate agent"""
if not state.get("query"):
return Command(update={"response": "No query provided"}, goto=END)
agent_list = {agent.id:agent.status for agent in self.available_agents}

#Do not route for custom agents
if state["agent_id"] in agent_list and agent_list[state["agent_id"]] != "SYSTEM":
return Command(update={"agent_id": state["agent_id"]}, goto=state["agent_id"])

# Classification using LLM with enhanced prompt
prompt = self.classifier_prompt.format(
query=state["query"],
agent_id=state["agent_id"],
agent_descriptions=self.agent_descriptions,
)

response = await self.llm.ainvoke(prompt)
response = response.content.strip("`")
try:
Expand Down

0 comments on commit 7aaa12d

Please sign in to comment.