WalkXR-AI / agent_utils / matching.py
matching.py
Raw
from typing import List
from schemas.goal_schema import Goal
from agent_utils.llm_interface import call_llm
from schemas.agent_schema import Agent

def find_best_goal(user_input: str, available_goals: List[Goal]) -> Goal:
    goal_list_str = "\n".join(
        f"{goal.name}: {goal.description}" for goal in available_goals
    )

    prompt = f"""
You are helping a user choose a goal that best fits their situation.

User said: "{user_input}"

Here are the available goals:
{goal_list_str}

Return ONLY the most relevant goal name (e.g., "order_coffee").
    """

    response = call_llm(prompt).strip().splitlines()[0].split()[0]
    match = next((g for g in available_goals if g.name == response), None)

    return match or available_goals[0]  # fallback

def find_best_matching_agent(goal: Goal, available_agents: List[Agent]) -> Agent:
    agent_list_str = "\n".join(
        f"{agent.name}: {agent.personality}, {agent.style}" for agent in available_agents
    )

    prompt = f"""
Given the user’s goal: "{goal.description}"

Choose the best agent from this list to help with that goal:

{agent_list_str}

Return ONLY the agent name (e.g., "Jamie").
    """

    response = call_llm(prompt).strip().splitlines()[0].split()[0]
    match = next((a for a in available_agents if a.name == response), None)
    return match or available_agents[0]