MetorialDocs

Use tools from several apps in one agent session

List one entry per provider deployment in the providers array of metorial.connect(). The session serves every tool, prefixed with its provider name.

To give one agent tools from several apps, list one entry per provider deployment in the providers array of metorial.connect(). The session serves all of their tools through one connection and prefixes each tool with its provider name, so tools from different apps cannot collide. Each entry carries its own auth and tool filter.

What you'll learn

  • How to deploy two providers from the CLI
  • How to attach both to one session in TypeScript and Python
  • How to mix per-user connections and filters in the same session

Before you start

With the CLI

Deploy two providers

Metorial Search and Metorial Crawl are built in and need no credentials. Copy both deployment IDs (pde_...).

metorial-admin providers deployments create --provider-id metorial-search --name "Metorial Search"
metorial-admin providers deployments create --provider-id metorial-crawl --name "Metorial Crawl"

Export the IDs

export SEARCH_DEPLOYMENT_ID="pde_..."
export CRAWL_DEPLOYMENT_ID="pde_..."

Optional: save the combination

A session template stores the list under one ID. Pass it as sessionTemplateId in a provider entry instead of repeating the list in code.

metorial-admin sessions templates create \
  --name "Research agent" \
  --providers '[{"provider_deployment_id": "pde_search_id"}, {"provider_deployment_id": "pde_crawl_id"}]'

With the SDK

Install the SDK and an adapter:

npm install metorial @metorial/ai-sdk ai
pip install metorial

Save this as session.ts or session.py. It attaches both deployments and prints the combined tool list. Pass session.tools() to your model SDK or framework as usual.

import { metorialAiSdk } from '@metorial/ai-sdk';
import Metorial from 'metorial';

let metorial = new Metorial({ apiKey: process.env.METORIAL_API_KEY! });

let session = await metorial.connect({
  adapter: metorialAiSdk(),
  providers: [
    { providerDeploymentId: process.env.SEARCH_DEPLOYMENT_ID! },
    { providerDeploymentId: process.env.CRAWL_DEPLOYMENT_ID! }
  ]
});

console.log(Object.keys(session.tools()).join(', '));
import asyncio
import os

from metorial import Metorial, metorial_openai


async def main():
    metorial = Metorial(api_key=os.environ["METORIAL_API_KEY"])

    session = await metorial.connect(
        adapter=metorial_openai(),
        providers=[
            {"provider_deployment_id": os.environ["SEARCH_DEPLOYMENT_ID"]},
            {"provider_deployment_id": os.environ["CRAWL_DEPLOYMENT_ID"]},
        ],
    )

    print(", ".join(tool["function"]["name"] for tool in session.tools()))


asyncio.run(main())

Mix auth and filters per app

Each entry is independent. This list gives an agent web search, one user's Slack account, and read access to the same user's GitHub account:

import { metorialAiSdk } from '@metorial/ai-sdk';
import Metorial from 'metorial';

let metorial = new Metorial({ apiKey: process.env.METORIAL_API_KEY! });

export let connectForUser = async (user: {
  slackAuthConfigId: string;
  githubAuthConfigId: string;
}) =>
  metorial.connect({
    adapter: metorialAiSdk(),
    providers: [
      { providerDeploymentId: process.env.SEARCH_DEPLOYMENT_ID! },
      {
        providerDeploymentId: process.env.SLACK_DEPLOYMENT_ID!,
        providerAuthConfigId: user.slackAuthConfigId
      },
      {
        providerDeploymentId: process.env.GITHUB_DEPLOYMENT_ID!,
        providerAuthConfigId: user.githubAuthConfigId,
        toolFilters: [{ type: 'tool_regex', pattern: '^(list|get|search)' }]
      }
    ]
  });
import os

from metorial import Metorial, metorial_openai

metorial = Metorial(api_key=os.environ["METORIAL_API_KEY"])


async def connect_for_user(slack_auth_config_id: str, github_auth_config_id: str):
    return await metorial.connect(
        adapter=metorial_openai(),
        providers=[
            {"provider_deployment_id": os.environ["SEARCH_DEPLOYMENT_ID"]},
            {
                "provider_deployment_id": os.environ["SLACK_DEPLOYMENT_ID"],
                "provider_auth_config_id": slack_auth_config_id,
            },
            {
                "provider_deployment_id": os.environ["GITHUB_DEPLOYMENT_ID"],
                "provider_auth_config_id": github_auth_config_id,
                "tool_filters": [{"type": "tool_regex", "pattern": "^(list|get|search)"}],
            },
        ],
    )

The auth config IDs come from the per-user OAuth flow. A session accepts up to 100 providers.

Check it worked

The program prints the tools of both providers and metorial_connection_status, the diagnostic tool Metorial adds to every session. The AI SDK adapter lowercases tool names, so the TypeScript program prints them in lower case.

metorial_connection_status, metorial_crawl_extractWebContent, metorial_search_getWebContent, metorial_search_webSearch

If a provider cannot be reached, the session still works. Ask the agent to call metorial_connection_status, or list the session's errors:

metorial-admin sessions errors list --limit 5

Troubleshooting

Cannot associate more than 100 providers to a session

Split the providers across sessions, or use fewer deployments.

Provider requires an auth config to be provided

One of the entries needs a sign-in and has no provider auth config. Add providerAuthConfigId to that entry.

Next steps