Files
Eduard van Valkenburg 36ce0950e4 Simplify Python hosting core (#6492)
Remove linking, multicast, durable delivery, and host push machinery from the v1 hosting core. Keep those scenarios in a proposed follow-up ADR and update channel packages, samples, docs, tests, and workspace metadata around the smaller host/channel contract.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-06-12 08:34:08 +02:00

1.6 KiB

local_telegram — @tool, file-backed history, hooks, Telegram

Builds on foundry_hosted_agent/ with the hooks and config most real apps need:

  • A @tool-decorated function call (get_weather) so streaming and tool invocation are exercised end-to-end.
  • FileHistoryProvider(./storage/sessions) so per-user/per-chat history survives restarts.
  • A responses_hook that keys each session off the OpenAI safety_identifier field, so multiple users on the Responses endpoint do not share history.
  • A telegram_hook that keys per-chat sessions via telegram_isolation_key.
  • Two extra Telegram commands (/new, /whoami).

app:app is a module-level Starlette ASGI app, so this sample runs under Hypercorn (multi-process).

Run

export FOUNDRY_PROJECT_ENDPOINT=https://<your-project>.services.ai.azure.com
export FOUNDRY_MODEL=gpt-4o
export TELEGRAM_BOT_TOKEN=...
az login

uv sync
uv run hypercorn app:app \
    --bind 0.0.0.0:8000 \
    --workers 4

Single-process for quick iteration:

uv run python app.py

Call locally

uv sync --group dev

# Plain call:
uv run python call_server.py "What is the weather in Tokyo?"

# Resume an existing session by AgentSession id (works across channels):
uv run python call_server.py --previous-response-id telegram:8741188429 "What did we discuss?"

This sample is local-only — it shows the agent-framework-hosting server stack as a standalone process. For a Foundry-Hosted-Agents-compatible packaging (Dockerfile + agent.yaml + azure.yaml), see foundry_hosted_agent/.