Glasser
GlasserToolkit gives AG2 agents six focused paid-data tools through Glasser. An application supplies one Glasser API key and selects which tools the agent may call.
Note
Each call can incur a charge. The toolkit uses AG2's existing httpx dependency. Set GLASSER_API_KEY in your environment; the toolkit does not read environment variables itself.
Tools#
Each tool uses one fixed action in a Glasser Solution endpoint. The model supplies only the inputs shown below. The application controls Provider choice, result limits, country, Task ID, metadata, and returned text length.
| Tool / factory | Model inputs | Glasser action |
|---|---|---|
glasser_web_search / web_search() | query | web_research.search |
glasser_company_profile / company_profile() | domain | company_intelligence.enrich |
glasser_find_people / find_people() | At least one of job_titles, locations, company_domain, keywords | people_search.search |
glasser_keyword_overview / keyword_overview() | Non-empty keywords list | seo_research.keyword_overview |
glasser_social_search / social_search() | platform, query | social_research.search |
glasser_stock_quote / stock_quote() | symbol | market_data.stock_quote |
The toolkit rejects empty required inputs before making a paid request. Glasser validates Provider support and the remaining request fields. Other Solution actions can be added as separate tools.
Select tools and set application options#
Passing the toolkit to an agent registers all six tools. Use factory methods to register a subset:
provider and metadata apply to all six tools. limit applies to web search, company profiles, people search, and keyword overviews. country applies to web search, company profiles, and keyword overviews. task_id applies to all except social search. The constructor passes its options to its six default tools. A factory called separately uses only its own options; omitted values let Glasser use its server defaults. Every factory also accepts name, description, and middleware.
limit is the application-controlled lever for result count and, where the Provider charges per result, cost. There is no universal per-call spending ceiling on these six actions. The model cannot change limit or select a more expensive action. Applications should register only the tools they intend to fund and set their own Glasser Workspace budget.
Options support AG2 Variable values:
A missing variable without a default raises KeyError before an HTTP request is sent.
Results and charges#
Tools return a typed GlasserResult with id, status, result_status, provider, charge_usd, output, error, failure, provider_response, runs, run_url, result_url, and truncated. An invalid input instead returns {"error": "..."} without a paid call.
status describes the Run lifecycle. result_status describes the Solution delivery outcome and can be success, partial, no_result, error, or pending. charge_usd is the exact USD decimal string returned by Glasser, or null until the listed Runs settle. A failed or empty result can still incur a charge. People search returns a native Run; its provider_response and output depend on the Provider.
max_characters limits the combined text in output, error, failure, and provider_response to 10,000 characters by default. A cut object is returned as a text excerpt, and truncated becomes true. The limit never cuts status, IDs, URLs, charges, or Run references. Set max_characters=None to keep all content. A pending result retains its retrieval URL or Run ID.
Async execution and retries#
For a pending result, the toolkit polls with authenticated GET requests: the returned result_url for normalized results, or GET /v1/runs/<id> for people search. Result URLs must refer to the same capability on the configured API origin. Redirects are not followed.
The default polling budget is 120 seconds, with a one-second interval. If it expires or a polling GET fails, the tool returns the latest pending result. wait_timeout=0 disables polling. To continue, use an authenticated GET to the result URL or Run endpoint. A new tool call can incur a new charge.
Each POST has an Idempotency-Key derived from the stream ID, tool-call ID, and capability. Replaying the same call in the same stream uses the same key. A different call or stream produces a new key. The toolkit does not retry POST requests automatically.
Connection settings#
Each execution opens an httpx.AsyncClient and closes it after its result is returned. A custom base_url can include a gateway path; the gateway must return result URLs on that same origin and path. The polling budget does not include the initial POST. HTTP errors raise httpx.HTTPStatusError, transport failures raise an httpx exception, and malformed JSON or a non-object response raises ValueError.
See the Solutions reference for Provider support, output contracts, and billing behavior.