Skip to content

Update service to interface with AI agents /insight/iteneraries endpoint#49

Closed
Copilot wants to merge 4 commits into
developmentfrom
copilot/update-insight-iteneraries-endpoint
Closed

Update service to interface with AI agents /insight/iteneraries endpoint#49
Copilot wants to merge 4 commits into
developmentfrom
copilot/update-insight-iteneraries-endpoint

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Nov 5, 2025

Updates the backend service layer to interface with the AI agents server's /api/v1/insight/iteneraries endpoint for getting insights on multiple itineraries at once.

Changes

Schema updates (app/schemas/ai_agents.py):

  • Updated ItineraryInsightRequest: itineraries: List[Itinerary], user_preferences: List[PreferenceBase]
  • Updated ItineraryInsightResponse: itenerary_insights: List[ItineraryInsight]
  • Added ItineraryInsight: ai_insight: str, leg_insights: List[LegInsight]
  • Added LegInsight: ai_insight: str

Service updates (app/services/ai_agents_service.py):

  • Updated get_itinerary_insight() to wrap the new batch API
  • Added get_itineraries_insight() that calls AI agents server at /api/v1/insight/iteneraries
  • Both methods modify itineraries in place for backward compatibility
  • Error handling for timeouts and non-200 responses

How It Works

The backend acts as an intermediary that interfaces with the AI agents server:

  1. Users call the routes search endpoint (/api/v1/routes/search)
  2. The routes endpoint internally calls get_itinerary_insight() for each itinerary
  3. The service makes HTTP requests to the AI agents server at /api/v1/insight/iteneraries
  4. Response insights are mapped back to enrich the itineraries in place
  5. Users receive routes with AI insights included

AI Agents API Contract

# Request to AI agents server
{
  "itineraries": [
    {
      "start": "2025-10-14T10:00:00Z",
      "end": "2025-10-14T10:45:00Z",
      "duration": 2700,
      "walk_distance": 500.0,
      "walk_time": 400,
      "legs": [...]
    }
  ],
  "user_preferences": [
    {"prompt": "prefer minimal walking"}
  ]
}

# Response from AI agents server
{
  "itenerary_insights": [
    {
      "ai_insight": "Convenient route with minimal walking",
      "leg_insights": [
        {"ai_insight": "Short walk to bus stop"},
        {"ai_insight": "Direct bus connection"}
      ]
    }
  ]
}

Note: The backend does NOT expose /api/v1/insight/iteneraries as a user-facing endpoint. It only interfaces with the AI agents server via HTTP. Spelling (iteneraries, itenerary_insights) matches the external AI agents API specification.

Original prompt

This section details on the original issue you should resolve

<issue_title>Change /insight/iteneraries</issue_title>
<issue_description>Change endpoint and schemas to match endpoint in Commute-ai/commute-ai-agents.

  1. Update the endpoint from insight/itinerary to /insight/iteneraries

  2. Update the Request and Response schema
    ItineraryInsightRequest:

  • itineraries: list[Itinerary]
  • user_preferences: list[PreferenceBase]

ItineraryInsightResponse:

  • itenerary_insights: list[ItineraryInsight]

ItineraryInsight:

  • ai_insight: str
  • leg_insights: list[LegInsight]

LegInsight:

  • ai_insight: str</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: zlendo1 <115471708+zlendo1@users.noreply.github.com>
Copilot AI changed the title [WIP] Change endpoint and schemas for /insight/iteneraries Add /insight/iteneraries endpoint for batch itinerary insights Nov 5, 2025
Copilot AI requested a review from zlendo1 November 5, 2025 19:39
@zlendo1
Copy link
Copy Markdown
Contributor

zlendo1 commented Nov 5, 2025

@copilot The /api/v1/insight/iteneraries endpoint doesn't exist in the backend. Rather, it is provided by the Commute-ai/commute-ai-agents server and only interfaced to by the backend through HTTP.

…rrectly

Co-authored-by: zlendo1 <115471708+zlendo1@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Nov 5, 2025

@copilot The /api/v1/insight/iteneraries endpoint doesn't exist in the backend. Rather, it is provided by the Commute-ai/commute-ai-agents server and only interfaced to by the backend through HTTP.

You're absolutely right. I've corrected the implementation in commit 8931feb.

The backend now only interfaces with the AI agents server via HTTP - it doesn't expose /api/v1/insight/iteneraries as a user-facing endpoint. Instead:

  1. Updated schemas to match the new API contract
  2. Modified the service to call the AI agents server's /api/v1/insight/iteneraries endpoint
  3. Removed the incorrectly created backend endpoint

The routes endpoint continues to work as before, but now uses the updated service method that calls the AI agents server.

Copilot AI changed the title Add /insight/iteneraries endpoint for batch itinerary insights Update service to interface with AI agents /insight/iteneraries endpoint Nov 5, 2025
@zlendo1
Copy link
Copy Markdown
Contributor

zlendo1 commented Nov 6, 2025

Parent issue #47 solved by #50.

@zlendo1 zlendo1 closed this Nov 6, 2025
@3nd3r1 3nd3r1 deleted the copilot/update-insight-iteneraries-endpoint branch November 11, 2025 13:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants