XquikSearchToolkit in ag2.extensions.tools.search, so Xquik tweet search reaches AG2 agents without a community adapter. AG2 documents the toolkit in its Xquik Tweet Search reference. Preserve every tweet ID and cursor the API returns.
Why Use AG2 With the Xquik Twitter API?
AG2 binds search parameters when a tool is constructed, not when the model calls it. The agent chooses the query. You choose the window, the ordering, and the result limit.
This suits research, monitoring, and reporting agents. Use direct REST for deterministic jobs that need no model decisions.
AG2 Twitter API Prerequisites
- Python 3.10 or later
- An Xquik API key beginning with
xq_ - An LLM provider key supported by AG2
Install AG2
XquikSearchToolkit calls the Xquik REST API over httpx, which AG2 already depends on. No extra package is required. Install your model provider extra as well.
.env
.gitignore
Register the Xquik Tweet Search Tool
Passing the toolkit to an agent registers one tool,xquik_tweet_search. It takes a single query argument holding an X search string.
api_key is required. The toolkit raises ValueError when it is empty, so a missing key fails at construction rather than on the first search.
Bind the Search Window Outside Model Control
Search defaults belong on the constructor. The model then cannot widen the window or raise the result limit.
The same parameters are available on the
search() factory method when you want several differently scoped tools from one toolkit.
Read the Structured Result
xquik_tweet_search returns a typed response rather than a raw payload.
Tweet records pass through unmodified, so every tweet ID, profile ID, and timestamp survives the hop into the agent. Feed
next_cursor back through the cursor parameter to continue pagination.
Resolve Values at Runtime With Variables
Every runtime parameter accepts an AG2Variable. AG2 resolves it from the run context when the tool executes, so one tool instance serves many users or tenants.
Delegate Search in a Multi-Agent Team
Agent.as_tool() exposes an agent as a tool for another agent. Each delegated task runs on its own stream with its own history. The coordinator receives the delegate’s final answer, not its internal tool-call history.
Handle Failures
The tool raises on non-success HTTP status codes throughhttpx. Read Error Handling for status semantics and Rate Limits for retry guidance. Wrap the toolkit with AG2 tool middleware when you need retries, approval gates, or audit logging around every search.