Skip to main content
Build a Microsoft Agent Framework agent that can search tweets, hand off IDs and cursors, post tweets, replay stored monitor events, and run extraction jobs - all through Xquik’s MCP server.

Prerequisites

  • Python 3.10+
  • Xquik API key (xq_...)
  • An LLM API key (OpenAI, Azure OpenAI, or any supported provider)

Install

The agent-framework meta-package installs the core framework, providers, and MCP support.

Full Example

The agent discovers explore and xquik, then can call 118 MCP operations. The MCP runtime returns normalized snake_case fields through xquik.request(), so keep prompts aligned with tweet_id, has_more, next_cursor, and returned job IDs.

Handoff Checklist

Tweet search rows

Store tweet_id, text, author_username, created_at, has_more, next_cursor, and the original q.

User profile rows

Store source id as user_id, plus username, name, followers, verified, profile_picture, has_more, next_cursor, and the source lookup or search query.

Trend rows

Store each trend name, rank, query, and description. Keep response count, woeid, and the requested region with the run checkpoint.

Monitor and webhook setup

Store the returned monitor id as monitor_id, event_types, next_billing_at, the returned webhook id as webhook_id, url, and the one-time secret in a secret manager. On production deliveries, store delivery_id for receiver retry de-dupe and stream_event_id when one monitor event should process once across endpoint changes.

Stored event replay

Store event_id, type, monitor_id, monitor_type, occurred_at, has_more, next_cursor, and the after query for the next page.

Extraction jobs

Store extraction_id, status, poll, and export_after_complete; poll before loading CSV, JSON, or XLSX rows.

Writes

Store tweet_id or write_action_id, reply_to_tweet_id, status, charged_credits, and poll; do not resend pending writes.

Media attachments

For tweets or replies, pass public URLs in media and store tweet_id or write_action_id. For DMs, upload first, pass one media_id in media_ids, store message_id, and leave reply_to_message_id unset.

Streaming Responses

Pass stream=True to run for real-time token streaming:

Multi-Agent Handoff

Keep data access in one agent, then pass its compact result to a separate analysis agent. This makes the MCP credential boundary explicit.

Per-Run Headers

Pass API keys through header_provider and function_invocation_kwargs for multi-tenant apps. The key remains scoped to the current run.
Do not close over a shared user’s key in header_provider. Resolve it from the current call’s function_invocation_kwargs.

Azure OpenAI

Use the same OpenAIChatClient with explicit Azure routing inputs:

Environment Variables

Store your API keys in a .env file instead of hardcoding them:
.env

Package Versions

Last modified on July 16, 2026