Sunday, 2 November 2025

Bring third party data into Declarative Agents for M365 Copilot (using TypeSpec)

In my previous post, Getting Started: Declarative Agents With TypeSpec for Microsoft 365 Copilot we saw the basics of Declarative Agents and how they are the sweet spot between no-code and pro-code agents. 

In this post, we will see how we can integrate third-party APIs in Declarative Agents. Declarative Agents can call third-party APIs through “actions” you describe in TypeSpec. The agent decides when to invoke your action, passes parameters, and you choose how the results render in chat (e.g Adaptive Cards). We’ll be plugging in a public weather API to show the end-to-end pattern.



On a high level, we’ll:

  • Scaffold a Declarative Agent in VS Code.

  • Add two actions: city → coords, then coords → weather.

  • Bind results to Adaptive Cards for clean output.

  • Test with natural prompts like “Weather in Paris, France”.

Prereqs

  • Microsoft 365 tenant + VS Code with the Microsoft 365 Agents Toolkit extension.

  • TypeSpec packages from the scaffold.

  • Public APIs (no auth):

    • Geocoding: https://geocoding-api.open-meteo.com/v1/search?name={city}&count=1

    • Weather: https://api.open-meteo.com/v1/forecast?latitude={lat}&longitude={lon}&current=temperature_2m,wind_speed_10m

1) Scaffold a TypeSpec Declarative Agent

Click path: VS Code → Microsoft 365 Agents Toolkit (sidebar) → Create a New Agent/AppDeclarative Agent (TypeSpec) → Finish. 


2) Add the TypeSpec files (agent + actions)

Update the main.tsp file:

And the actions.tsp file containing the action details

3) Add Adaptive Cards

Create adaptiveCards/ and add:

adaptiveCards/location-card.json

adaptiveCards/weather-card.json


4) Build & test

  • In Agents Toolkit: Provision.

  • Open the web test for your agent and try:

Prompts

  • “What’s the weather in Seattle right now?”

  • “Show me the weather in Paris, France.”

  • “Get weather for latitude 40.7128 and longitude -74.0060.”

Expected

  • The agent calls searchCity (shows Location card) → then getWeather (shows Weather card with °C, wind, time, timezone)



Minimal working example

Prompt: “Weather for Pune.”

Flow: searchCity(name="Pune") → top match → getWeather(latitude, longitude, current="temperature_2m,wind_speed_10m", location="Pune, IN")


Output: Two cards; final card shows temperature (°C), wind (km/h), time, and timezone.

Wrapping up

Declarative Agents make third-party API calls feel native: describe the action, let the agent orchestrate, and render the result with Adaptive Cards. 

Hope this helps!