The scripts/model_examples/ directory provides a comprehensive suite of verification scripts for the LLM providers supported by AgentScope. These scripts serve as both integration tests and technical references for developers, demonstrating how to interact with model adapters directly, handle streaming reasoning, execute tool calling, and manage multimodal inputs.
The examples are organized by provider and suffixed by the specific capability they demonstrate.
| Suffix | File Pattern | Verification Scope |
|---|---|---|
call | *_call.py | Simple text interaction, two-round tool calling, and structured JSON output via generate_structured_output. |
multiagent | *_multiagent.py | Multi-party conversations utilizing specialized MultiAgentFormatter implementations. |
multimodal | *_multimodal.py | Processing of DataBlock objects containing images, audio, or video. |
multiagent_multimodal | *_multiagent_multimodal.py | Combined scenarios where multimodal content is shared within a multi-agent context. |
Sources: scripts/model_examples/README.md8-70
run_tests.py)The run_tests.py script provides a centralized interface for executing the example suite. It features automatic provider detection based on environment variables and generates a summary report of the results.
The runner identifies available providers by checking for specific environment variables:
OPENAI_API_KEY (Chat Completions API) scripts/model_examples/README.md77OPENAI_API_KEY (Responses API for o1/o3/o4-mini) scripts/model_examples/README.md78ANTHROPIC_API_KEY (Claude models) scripts/model_examples/README.md79DASHSCOPE_API_KEY (Qwen series) scripts/model_examples/README.md80DEEPSEEK_API_KEY scripts/model_examples/README.md81GEMINI_API_KEY scripts/model_examples/README.md82MOONSHOT_API_KEY scripts/model_examples/README.md83XAI_API_KEY (Grok models) scripts/model_examples/README.md84http://localhost:11434 scripts/model_examples/README.md85Sources: scripts/model_examples/README.md73-86 scripts/model_examples/README.md112-124
The following diagram illustrates the relationship between the test runner, the utility helpers, and the provider-specific scripts.
Title: Model Example Execution Flow
Sources: scripts/model_examples/run_tests.py1-200 scripts/model_examples/_utils.py15-104 scripts/model_examples/openai_chat_call.py71-134
_utils.pyThe stream_and_collect function in _utils.py is the primary helper for consuming AsyncGenerator[ChatResponse, None] outputs from model calls.
stream_and_collect:ThinkingBlock instances and prints them with a [Thinking] prefix scripts/model_examples/_utils.py42-46TextBlock content incrementally as it arrives scripts/model_examples/_utils.py47-53DataBlock chunks (e.g., streaming audio), it tracks chunk counts and cumulative byte sizes scripts/model_examples/_utils.py54-74ChatResponse (where is_last=True) which contains the complete accumulated content, allowing the caller to inspect ToolCallBlock objects without re-processing the stream scripts/model_examples/_utils.py38-40 scripts/model_examples/_utils.py104Sources: scripts/model_examples/_utils.py15-104
The example scripts follow a standardized pattern for verifying three core LLM capabilities.
The *_call.py scripts demonstrate a two-round interaction for tool calling. Note that the OpenAI Responses API requires using call_id for matching tool results scripts/model_examples/openai_response_call.py117-125
Title: Tool Call Verification Pattern
Sources: scripts/model_examples/openai_chat_call.py71-134 scripts/model_examples/xai_call.py76-137 scripts/model_examples/openai_response_call.py77-141
Scripts verify the generate_structured_output method by passing a Pydantic BaseModel (e.g., MathSolution). The model is expected to return a JSON object matching the schema, which AgentScope parses into the content field of the response.
Sources: scripts/model_examples/openai_chat_call.py150-186 scripts/model_examples/gemini_call.py150-181 scripts/model_examples/deepseek_call.py151-184
Multi-agent scripts demonstrate the use of provider-specific formatters, such as GeminiMultiAgentFormatter scripts/model_examples/gemini_multiagent_multimodal.py20 to flatten conversation history. Multimodal scripts utilize DataBlock with URLSource scripts/model_examples/gemini_multiagent_multimodal.py36-38 or Base64Source to send media.
Sources: scripts/model_examples/gemini_multiagent_multimodal.py18-89 scripts/model_examples/openai_chat_call.py1-191
To list available providers and their environment variable status:
To run specific tests (e.g., only basic calls for OpenAI and Anthropic):
Individual scripts can be run directly if the environment variables are set. For Ollama, the server must be running locally:
Sources: scripts/model_examples/README.md89-207 scripts/model_examples/ollama_call.py4-9
Refresh this wiki