repo stringclasses 454
values | file_path stringlengths 5 201 | extension stringclasses 1
value | content stringlengths 8 509k | num_lines int64 3 16.9k | size_bytes int64 8 511k |
|---|---|---|---|---|---|
agentscope | tests/tts_middleware_test.py | .py | # -*- coding: utf-8 -*-
"""Unit tests for TTSMiddleware."""
import base64
from typing import Any, AsyncGenerator
from unittest import IsolatedAsyncioTestCase
from unittest.mock import AsyncMock, MagicMock
from agentscope import set_id_factory
from agentscope.event import (
DataBlockDeltaEvent,
DataBlockEndEven... | 427 | 13,948 |
agentscope | tests/task_tool_test.py | .py | # -*- coding: utf-8 -*-
"""Unit tests for task tools."""
from unittest.async_case import IsolatedAsyncioTestCase
from utils import AnyString
from agentscope.state import AgentState
from agentscope.tool import TaskCreate, TaskGet, TaskList, TaskUpdate
class TestTaskCreate(IsolatedAsyncioTestCase):
"""Test cases ... | 999 | 33,000 |
agentscope | tests/service_inbox_middleware_test.py | .py | # -*- coding: utf-8 -*-
# pylint: disable=abstract-method,protected-access
"""Tests for :class:`InboxMiddleware`.
Every cross-session message delivery in the framework (team messages
via ``TeamSay`` / ``AgentCreate``, background-tool completion results,
scheduler fires) goes through this middleware on the consumer sid... | 517 | 15,963 |
agentscope | tests/mem0_middleware_test.py | .py | # -*- coding: utf-8 -*-
# pylint: disable=protected-access,unused-argument
"""Unit tests for Mem0Middleware.
The mem0 client itself is mocked — we only exercise the AgentScope hook
wiring (retrieve-before / write-after, system-prompt injection,
list_tools exposure) and the small adapter that translates between
AgentSc... | 892 | 34,312 |
agentscope | tests/formatter_openai_response_test.py | .py | # -*- coding: utf-8 -*-
"""Comprehensive formatter unit tests for OpenAIResponseFormatter and
OpenAIResponseMultiAgentFormatter, following the reference test style with
exact ground-truth comparisons.
Key differences from OpenAI Chat formatter:
- Text content type is "input_text" (not "text").
- Image content type... | 977 | 32,808 |
agentscope | tests/service_workspace_status_test.py | .py | # -*- coding: utf-8 -*-
"""``GET /workspace/status`` test case.
The endpoint's whole job beyond composing a response is refusing to fail
loudly. ``exec_shell`` reports trouble inconsistently across backends —
Docker and K8s raise, the rest fold everything into a non-zero
``ExecResult`` — and a directory that is simply... | 306 | 10,600 |
agentscope | tests/backend_docker_test.py | .py | # -*- coding: utf-8 -*-
# pylint: disable=protected-access
"""Test cases for :class:`DockerBackend`.
Validates that the three backend primitives (``exec_shell``,
``read_file``, ``write_file``) and the inherited shell-based filesystem
helpers behave correctly inside a real Docker container.
The suite is skipped unless... | 215 | 9,156 |
agentscope | tests/workspace_k8s_test.py | .py | # -*- coding: utf-8 -*-
# pylint: disable=protected-access
"""Integration tests for :class:`K8sWorkspace`.
These tests exercise a real Kubernetes cluster (kind is used in CI).
The whole module is skipped when either:
* the current platform is not Linux, or
* ``K8S_TEST_IMAGE`` is not set (the pre-baked test image nam... | 449 | 15,871 |
agentscope | tests/skill_loader_test.py | .py | # -*- coding: utf-8 -*-
# pylint: disable=protected-access
"""Test cases for LocalSkillLoader."""
import os
import tempfile
import shutil
import time
from unittest.async_case import IsolatedAsyncioTestCase
from unittest.mock import patch
from agentscope.skill import LocalSkillLoader
class SkillLoaderTest(IsolatedAsy... | 268 | 9,335 |
agentscope | tests/backend_daytona_test.py | .py | # -*- coding: utf-8 -*-
# pylint: disable=protected-access
"""Test cases for :class:`DaytonaBackend`.
A live smoke suite exercises the real SDK mapping and is skipped unless
``DAYTONA_API_KEY`` is set.
"""
import unittest
from collections.abc import AsyncIterator
from contextlib import asynccontextmanager
from unitte... | 223 | 8,895 |
agentscope | tests/formatter_xai_test.py | .py | # -*- coding: utf-8 -*-
"""Comprehensive formatter unit tests for XAIChatFormatter and
XAIMultiAgentFormatter (xAI), following the reference test style.
Because these formatters return xai_sdk protobuf Message objects (not plain
dicts), a lightweight xai_sdk stub is built at module load so that tests run
without the r... | 597 | 20,199 |
agentscope | tests/service_enqueue_index_task_test.py | .py | # -*- coding: utf-8 -*-
# pylint: disable=protected-access
"""Tests for :func:`agentscope.app._bus_ops.enqueue_index_task`.
The helper is a three-line composition over two bus primitives —
``queue_push`` and ``publish`` — so the tests verify only that:
- the queued payload carries the three fields the
:class:`~agen... | 155 | 5,265 |
agentscope | tests/service_git_status_parse_test.py | .py | # -*- coding: utf-8 -*-
# pylint: disable=protected-access
"""Git status parser test case — pure functions, no git binary needed.
``porcelain=v2`` is a stable documented format, but three of its corners
are easy to get wrong and each is asserted below: a rename record spans
two NUL-separated fields under ``-z``, ``bra... | 243 | 9,071 |
agentscope | tests/tts_gemini_test.py | .py | # -*- coding: utf-8 -*-
# pylint: disable=protected-access
"""Unit tests for the Gemini TTS module.
Covers:
* ``GeminiTTSModel`` non-streaming synthesis from ``generateContent``
responses with ``responseModalities: ["AUDIO"]``.
* Handling of empty/missing text and empty audio responses.
"""
import base64
impor... | 184 | 6,552 |
agentscope | tests/formatter_openai_chat_test.py | .py | # -*- coding: utf-8 -*-
"""Comprehensive formatter unit tests for OpenAIChatFormatter and
OpenAIMultiAgentFormatter, following the reference test style with exact
ground-truth comparisons.
"""
from unittest import IsolatedAsyncioTestCase
from unittest.mock import patch
from agentscope.formatter import (
OpenAIChat... | 773 | 26,118 |
agentscope | tests/hitl_user_confirmation_test.py | .py | # -*- coding: utf-8 -*-
# pylint: disable=redefined-builtin
"""Test the user confirmation events in the agent class."""
from typing import Any
from unittest.async_case import IsolatedAsyncioTestCase
from utils import AnyString, MockModel
from agentscope.agent import Agent, InjectionConfig
from agentscope.model import ... | 1,832 | 65,743 |
agentscope | tests/service_classify_error_test.py | .py | # -*- coding: utf-8 -*-
"""Unit tests for :func:`_classify_error` — the fatal-reply exception
classifier that feeds the UI ``ErrorInfo``.
These lock down the behaviour that regressed silently before: status codes
live in different places across clients (``status_code`` on the exception
for openai/anthropic, ``response... | 155 | 6,039 |
agentscope | tests/agent_basic_test.py | .py | # -*- coding: utf-8 -*-
"""The basic test of the agent class."""
from typing import Any
from unittest.async_case import IsolatedAsyncioTestCase
from utils import AnyString, MockModel
from agentscope.agent import Agent, ContextConfig, InjectionConfig, ReActConfig
from agentscope.model import ChatResponse
from agentsco... | 1,689 | 58,703 |
agentscope | tests/workspace_docker_test.py | .py | # -*- coding: utf-8 -*-
# pylint: disable=protected-access
"""Test cases for DockerWorkspace.
Mirrors the structure of ``workspace_local_test.py`` so that the two
backends are validated against the same surface contract:
* offload_context (text + DataBlock + dedup)
* offload_tool_result (string + multimodal blocks)
*... | 834 | 29,765 |
agentscope | tests/service_workspace_files_test.py | .py | # -*- coding: utf-8 -*-
"""Tests for the workspace file-browsing endpoints.
These are lightweight unit tests that do not require ``create_app``.
Dependencies are injected by calling the endpoint coroutines directly,
which avoids pulling a full FastAPI / Redis stack.
"""
from __future__ import annotations
import posi... | 597 | 21,684 |
agentscope | tests/permission_engine_test.py | .py | # -*- coding: utf-8 -*-
"""Test cases for PermissionEngine.
Mode-specific tests live in :mod:`tests.permission_mode_test`. This file
covers rule priority, rule pattern matching (Bash / file glob), dangerous
path detection, suggestion generation, Bash read-only command analysis,
and bypass-immune safety checks.
"""
imp... | 823 | 29,064 |
agentscope | tests/workspace_manager_applecontainer_test.py | .py | # -*- coding: utf-8 -*-
# pylint: disable=protected-access
# mypy: disable-error-code="misc,no-untyped-def,attr-defined"
"""Test cases for :class:`AppleContainerWorkspaceManager`."""
import asyncio
from unittest.async_case import IsolatedAsyncioTestCase
from unittest.mock import patch
from agentscope.app.workspace_ma... | 228 | 7,606 |
agentscope | tests/resource_access_policy_test.py | .py | # -*- coding: utf-8 -*-
"""Tests for resource access policy primitives."""
from typing import cast
from unittest.async_case import IsolatedAsyncioTestCase
from fastapi import HTTPException
from utils import AnyValue
from agentscope.app.access import (
DenyAllResourceAccessPolicy,
ResourceAccessPolicyBase,
... | 468 | 14,663 |
agentscope | tests/blob_store_s3_test.py | .py | # -*- coding: utf-8 -*-
"""Tests for :class:`S3BlobStore`.
Uses ``moto.server.ThreadedMotoServer``: a real HTTP S3 endpoint
served in-process on a thread. The aioboto3 client talks to it over
TCP the way it would talk to AWS / MinIO / R2 — so the test
exercises the real wire path (and the ``endpoint_url`` plumbing the... | 160 | 5,925 |
agentscope | tests/workspace_bubblewrap_test.py | .py | # -*- coding: utf-8 -*-
# pylint: disable=protected-access,consider-using-with
"""Tests for Bubblewrap workspace and manager."""
from __future__ import annotations
import base64
import asyncio
import json
import os
import shutil
import stat
import subprocess
import sys
import tempfile
import time
import unittest
impo... | 1,277 | 46,642 |
agentscope | tests/channel_routing_test.py | .py | # -*- coding: utf-8 -*-
"""Tests for channel routing — the pure ``resolve`` function that maps an
inbound event to ``(agent_id, session_id)``.
Covers: catch-all default, first-match-wins ordering, per_chat vs
per_chat_user session grouping, agent id embedded in the session id, and
determinism across calls.
"""
from un... | 173 | 6,049 |
agentscope | tests/rag_vdb_elasticsearch_test.py | .py | # -*- coding: utf-8 -*-
# pylint: disable=protected-access,missing-function-docstring
"""Unit tests for the ElasticsearchStore class."""
from __future__ import annotations
from contextlib import AsyncExitStack
from typing import Any
from unittest.async_case import IsolatedAsyncioTestCase
from unittest.mock import Asyn... | 250 | 8,768 |
agentscope | tests/tts_openai_test.py | .py | # -*- coding: utf-8 -*-
# pylint: disable=protected-access
"""Unit tests for the OpenAI TTS model.
Covers:
* ``OpenAITTSModel`` non-streaming aggregation.
* ``OpenAITTSModel`` streaming: incremental chunks and ``is_last``
placement at the final chunk only.
* Edge cases: empty/None input short-circuits withou... | 165 | 6,052 |
agentscope | tests/storage_sql_test.py | .py | # -*- coding: utf-8 -*-
# pylint: disable=too-many-public-methods
"""Round-trip and semantic tests for :class:`AsyncSQLAlchemyStorage`.
Runs against an in-memory SQLite database via ``sqlite+aiosqlite``
so the whole suite is self-contained — no external server needed.
The intent is to exercise every ``StorageBase`` me... | 989 | 35,875 |
agentscope | tests/mem0_agentscope_adapter_test.py | .py | # -*- coding: utf-8 -*-
# pylint: disable=wrong-import-order
"""Unit tests for the AgentScope ↔ mem0 adapters.
Verifies that ``AgentScopeLLM`` / ``AgentScopeEmbedding`` correctly
translate between mem0's sync OpenAI-style contract and AgentScope's
async ``Msg`` / ``ContentBlock`` / ``EmbeddingResponse`` shapes, and
th... | 463 | 17,464 |
agentscope | tests/service_knowledge_base_upload_test.py | .py | # -*- coding: utf-8 -*-
# pylint: disable=protected-access
"""End-to-end wiring test for the knowledge-base upload pipeline.
Boots the full FastAPI app via :func:`create_app` against fakeredis +
in-memory KB-side fakes, then drives the upload → status → list →
delete flow through ``TestClient``. Verifies that:
* ``c... | 452 | 15,666 |
agentscope | tests/event_to_message_test.py | .py | # -*- coding: utf-8 -*-
"""Unit tests for Msg.append_event – event-stream-to-Msg accumulation.
The test drives a single Msg object through a full, realistic streaming
sequence and asserts the complete model_dump() after every individual event.
Coverage
--------
* TextBlock : start / delta (×2) / end
* ThinkingBlock ... | 1,042 | 33,554 |
agentscope | tests/workspace_applecontainer_test.py | .py | # -*- coding: utf-8 -*-
# pylint: disable=protected-access
# mypy: disable-error-code="misc,no-untyped-def,attr-defined"
"""Test cases for :class:`AppleContainerWorkspace`.
Runs against a real Apple Container via the ``container`` CLI.
Requires ``container`` CLI installed and ``container system start``
running.
"""
i... | 475 | 17,281 |
agentscope | tests/formatter_moonshot_test.py | .py | # -*- coding: utf-8 -*-
"""Comprehensive formatter unit tests for MoonshotChatFormatter and
MoonshotMultiAgentFormatter, following the reference test style with exact
ground-truth comparisons.
"""
import base64
from unittest import IsolatedAsyncioTestCase
from unittest.mock import patch, MagicMock
from agentscope.form... | 827 | 28,196 |
agentscope | tests/model_moonshot_test.py | .py | # -*- coding: utf-8 -*-
# pylint: disable=protected-access
"""Unit tests for MoonshotChatModel with mocked API responses.
Tests cover both non-streaming and streaming modes.
"""
from typing import Any
import unittest
from unittest import IsolatedAsyncioTestCase
from unittest.mock import AsyncMock, MagicMock
from util... | 541 | 16,664 |
agentscope | tests/builtin_read_test.py | .py | # -*- coding: utf-8 -*-
"""Read tool test case."""
import os
import tempfile
from unittest.async_case import IsolatedAsyncioTestCase
from agentscope.tool import ToolChunk, Read
from agentscope.permission import (
PermissionContext,
PermissionBehavior,
PermissionRule,
)
from agentscope.message import TextBl... | 189 | 6,226 |
agentscope | tests/backend_local_test.py | .py | # -*- coding: utf-8 -*-
"""Test cases for :class:`LocalBackend` and the backend helpers.
Exercises the three abstract primitives (``exec_shell``, ``read_file``,
``write_file``) plus the derived filesystem helpers (``file_exists``,
``is_dir``, ``list_dir``, ``scandir``, ``read_stream``, ``stat_mtime``,
``delete_path``)... | 397 | 15,904 |
agentscope | tests/session_config_patch_test.py | .py | # -*- coding: utf-8 -*-
"""``PATCH /sessions/{id}`` test case — write isolation and cwd storage.
The endpoint has to keep two writers apart. Configuration is written by
this handler; ``AgentState`` is written by the chat run's ``_persist()``,
which completes while the run still holds the session lock. Two rules
follow... | 305 | 11,856 |
agentscope | tests/mcp_sse_client_test.py | .py | # -*- coding: utf-8 -*-
"""The MCP client test module in agentscope."""
import asyncio
import json
from multiprocessing import Process
from unittest.async_case import IsolatedAsyncioTestCase
from mcp.server import FastMCP
from pydantic import BaseModel
from agentscope.mcp import MCPClient, HttpMCPConfig
from agentsco... | 377 | 12,331 |
agentscope | tests/backend_bubblewrap_test.py | .py | # -*- coding: utf-8 -*-
# pylint: disable=protected-access,consider-using-with,too-many-public-methods
"""Test cases for :class:`BubblewrapBackend`."""
import os
import shutil
import stat
import subprocess
import sys
import tempfile
import unittest
import asyncio
from unittest.async_case import IsolatedAsyncioTestCase... | 573 | 22,682 |
agentscope | tests/tool_middleware_test.py | .py | # -*- coding: utf-8 -*-
# pylint: disable=unused-argument
"""Test cases for the tool-level onion middleware mechanism."""
from typing import Any, AsyncGenerator
from unittest.async_case import IsolatedAsyncioTestCase
from utils import AnyString
from agentscope.tool import (
ToolBase,
ToolMiddlewareBase,
T... | 353 | 11,871 |
agentscope | tests/rag_vdb_milvus_lite_test.py | .py | # -*- coding: utf-8 -*-
"""Unit tests for the MilvusLiteStore class."""
import tempfile
import unittest
from contextlib import AsyncExitStack
from importlib.util import find_spec
from pathlib import Path
from unittest.async_case import IsolatedAsyncioTestCase
from utils import AnyString
from agentscope.message import... | 363 | 12,111 |
agentscope | tests/storage_redis_knowledge_base_test.py | .py | # -*- coding: utf-8 -*-
# pylint: disable=protected-access
"""Unit tests for the knowledge base persistence layer of RedisStorage."""
from unittest.async_case import IsolatedAsyncioTestCase
import fakeredis.aioredis
from agentscope.app.storage import (
EmbeddingModelConfig,
KnowledgeBaseData,
KnowledgeBas... | 114 | 4,098 |
agentscope | tests/backend_opensandbox_test.py | .py | # -*- coding: utf-8 -*-
# pylint: disable=protected-access
"""Test cases for :class:`OpenSandboxBackend`.
Validates that the three backend primitives (``exec_shell``,
``read_file``, ``write_file``) and the inherited shell-based filesystem
helpers behave correctly inside a real OpenSandbox sandbox.
The whole module is... | 156 | 7,023 |
agentscope | tests/builtin_write_test.py | .py | # -*- coding: utf-8 -*-
"""Write tool test case."""
import os
import tempfile
from unittest.async_case import IsolatedAsyncioTestCase
from agentscope.tool import Write
from agentscope.permission import (
PermissionContext,
PermissionBehavior,
PermissionRule,
)
from agentscope.state import AgentState
from a... | 213 | 7,061 |
agentscope | tests/formatter_dashscope_test.py | .py | # -*- coding: utf-8 -*-
"""Comprehensive formatter unit tests for DashScopeChatFormatter and
DashScopeMultiAgentFormatter, following the reference test style with exact
ground-truth comparisons.
"""
from unittest import IsolatedAsyncioTestCase
from unittest.mock import mock_open, patch
from agentscope.formatter import... | 1,152 | 39,360 |
agentscope | tests/embedding_dashscope_test.py | .py | # -*- coding: utf-8 -*-
# pylint: disable=protected-access,unused-argument
"""Unit tests for DashScopeEmbeddingModel."""
from dataclasses import asdict
from typing import Any
from unittest import IsolatedAsyncioTestCase
from unittest.mock import AsyncMock, MagicMock, patch
from utils import AnyValue
from agentscope.c... | 234 | 8,149 |
agentscope | tests/service_cancel_dispatcher_test.py | .py | # -*- coding: utf-8 -*-
# pylint: disable=protected-access
"""Tests for :class:`CancelDispatcher` — one-per-process consumer of the
shared session-cancel broadcast channel.
Verifies that on each incoming ``session_id`` the dispatcher:
- Cancels the chat-run task in :class:`ChatRunRegistry` when it owns one
locally.... | 482 | 15,983 |
agentscope | tests/service_subagent_hitl_projector_test.py | .py | # -*- coding: utf-8 -*-
# pylint: disable=protected-access
"""Tests for :class:`SubagentHitlProjector` — the strategy that mirrors a
team *member* (worker) session's HITL request onto its *leader* session.
Covers the projection policy:
- A worker ``Require*`` event upserts a pending card on the leader and
publishes... | 366 | 12,478 |
agentscope | tests/model_base_test.py | .py | # -*- coding: utf-8 -*-
"""Unit tests for :class:`agentscope.model.ChatModelBase.__call__` — the
retry / accumulation / interrupt wrapper around ``_call_api``."""
import asyncio
import base64
from unittest.async_case import IsolatedAsyncioTestCase
from utils import AnyString, MockModel
from agentscope.message import ... | 1,071 | 37,914 |
agentscope | tests/hub_claw_test.py | .py | # -*- coding: utf-8 -*-
"""ClawHub card-building test case, without any network."""
from unittest import TestCase
from agentscope.app.hub import ClawSkillHub
class ClawCardTest(TestCase):
"""Turning an upstream catalog record into a ``SkillCard``."""
def setUp(self) -> None:
"""Build a hub with no t... | 171 | 6,714 |
agentscope | tests/test_e2e_e2b_mcp.py | .py | # -*- coding: utf-8 -*-
# pylint: disable=protected-access
"""E2E test: per-scope MCP isolation via E2BWorkspace.
Requires: ``E2B_API_KEY`` environment variable.
"""
import os
import unittest
from agentscope.workspace import E2BWorkspace
from agentscope.mcp import MCPClient, StdioMCPConfig
# ── minimal MCP stdio se... | 177 | 5,660 |
agentscope | tests/message_test.py | .py | # -*- coding: utf-8 -*-
"""A template test case."""
from unittest.async_case import IsolatedAsyncioTestCase
from utils import AnyString
from agentscope.message import (
UserMsg,
TextBlock,
DataBlock,
URLSource,
Base64Source,
ThinkingBlock,
AssistantMsg,
HintBlock,
Msg,
ToolCallB... | 315 | 10,049 |
agentscope | scripts/model_examples/openai_response_multiagent_multimodal.py | .py | # -*- coding: utf-8 -*-
"""Example of OpenAI Responses API model calls with MultiAgentFormatter and
image input."""
import asyncio
import os
from _utils import stream_and_collect
from agentscope.formatter import OpenAIResponseMultiAgentFormatter
from agentscope.message import Msg, TextBlock, DataBlock, URLSource
from ... | 91 | 2,569 |
agentscope | scripts/model_examples/openai_response_multimodal.py | .py | # -*- coding: utf-8 -*-
"""Example of OpenAI Responses API model multimodal (vision) calls using
DataBlock."""
import asyncio
import base64
import os
from pathlib import Path
from _utils import stream_and_collect
from agentscope.message import (
Msg,
TextBlock,
DataBlock,
URLSource,
Base64Source,
)... | 139 | 3,660 |
agentscope | scripts/model_examples/_utils.py | .py | # -*- coding: utf-8 -*-
"""Shared utility helpers for model-examples scripts."""
import base64 as _b64
from typing import AsyncGenerator
from agentscope.message import (
TextBlock,
ThinkingBlock,
DataBlock,
Base64Source,
)
from agentscope.model import ChatResponse
async def stream_and_collect(
ge... | 105 | 3,935 |
agentscope | scripts/model_examples/gemini_multiagent_multimodal.py | .py | # -*- coding: utf-8 -*-
"""Example of Gemini model calls with MultiAgentFormatter and image input."""
import asyncio
import os
from _utils import stream_and_collect
from agentscope.formatter import GeminiMultiAgentFormatter
from agentscope.message import Msg, TextBlock, DataBlock, URLSource
from agentscope.model impor... | 94 | 2,666 |
agentscope | scripts/model_examples/gemini_call.py | .py | # -*- coding: utf-8 -*-
"""Examples of Google Gemini model calls."""
import asyncio
import json
import os
from pydantic import BaseModel, Field
from _utils import stream_and_collect
from agentscope.message import (
Msg,
TextBlock,
ToolCallBlock,
ToolResultBlock,
ToolResultState,
)
from agentscope.... | 192 | 5,412 |
agentscope | scripts/model_examples/moonshot_call.py | .py | # -*- coding: utf-8 -*-
"""Examples of Moonshot AI model calls."""
import asyncio
import json
import os
from pydantic import BaseModel, Field
from _utils import stream_and_collect
from agentscope.message import (
Msg,
TextBlock,
ToolCallBlock,
ToolResultBlock,
ToolResultState,
)
from agentscope.mo... | 181 | 5,100 |
agentscope | scripts/model_examples/ollama_multiagent_multimodal.py | .py | # -*- coding: utf-8 -*-
"""Example of Ollama model calls with MultiAgentFormatter and image input.
Requires a multimodal Ollama model such as llava. Run `ollama pull llava`
first.
"""
import asyncio
from _utils import stream_and_collect
from agentscope.formatter import OllamaMultiAgentFormatter
from agentscope.messag... | 92 | 2,515 |
agentscope | scripts/model_examples/openai_response_call.py | .py | # -*- coding: utf-8 -*-
"""Examples of OpenAI Responses API model calls.
The Responses API (vs Chat Completions API) provides first-class streaming
events for reasoning/thinking content, making it a natural fit for reasoning
models such as o3 and o4-mini.
"""
import asyncio
import json
import os
from pydantic import ... | 200 | 5,812 |
agentscope | scripts/model_examples/anthropic_multiagent_multimodal.py | .py | # -*- coding: utf-8 -*-
"""Example of Anthropic Claude model calls with MultiAgentFormatter and
image input.
Demonstrates combining AnthropicMultiAgentFormatter with multimodal (vision)
content: Alice shares an image in a multi-agent conversation, and the model
is asked to summarize what everyone is looking at.
"""
im... | 100 | 2,905 |
agentscope | scripts/model_examples/moonshot_multiagent_multimodal.py | .py | # -*- coding: utf-8 -*-
"""Example of Moonshot model calls with MoonshotMultiAgentFormatter and
image input."""
import asyncio
import os
from _utils import stream_and_collect
from agentscope.formatter import MoonshotMultiAgentFormatter
from agentscope.message import Msg, TextBlock, DataBlock, URLSource
from agentscope... | 92 | 2,626 |
agentscope | scripts/model_examples/xai_multiagent_multimodal.py | .py | # -*- coding: utf-8 -*-
"""Example of Grok (xAI) model calls with XAIMultiAgentFormatter and image
input.
Note: Vision (image) input requires grok-4.3 or above.
"""
import asyncio
import os
from _utils import stream_and_collect
from agentscope.formatter import XAIMultiAgentFormatter
from agentscope.message import Msg... | 94 | 2,575 |
agentscope | scripts/model_examples/ollama_multiagent.py | .py | # -*- coding: utf-8 -*-
"""Example of Ollama model calls with OllamaMultiAgentFormatter.
The multi-agent formatter wraps prior conversation history in
<history></history> tags, enabling the model to handle multi-agent
conversations where more than one non-user agent is involved.
"""
import asyncio
from _utils import ... | 97 | 2,695 |
agentscope | scripts/model_examples/moonshot_multimodal.py | .py | # -*- coding: utf-8 -*-
"""Example of Moonshot model multimodal (vision) calls using DataBlock."""
import asyncio
import base64
import os
from pathlib import Path
from _utils import stream_and_collect
from agentscope.message import (
Msg,
TextBlock,
DataBlock,
URLSource,
Base64Source,
)
from agents... | 138 | 3,699 |
agentscope | scripts/model_examples/xai_multiagent.py | .py | # -*- coding: utf-8 -*-
"""Example of Grok (xAI) model calls with XAIMultiAgentFormatter.
The multi-agent formatter wraps prior conversation history in
<history></history> tags within a user protobuf message, enabling the xAI
Grok model to handle multi-agent conversations where more than one non-user
agent is involved... | 102 | 2,806 |
agentscope | scripts/model_examples/openai_chat_multimodal.py | .py | # -*- coding: utf-8 -*-
"""Example of OpenAI Chat model multimodal (vision) calls using DataBlock."""
import asyncio
import base64
import os
from pathlib import Path
from _utils import stream_and_collect
from agentscope.message import (
Msg,
TextBlock,
DataBlock,
URLSource,
Base64Source,
)
from age... | 195 | 5,207 |
agentscope | scripts/model_examples/deepseek_multiagent.py | .py | # -*- coding: utf-8 -*-
"""Example of DeepSeek model calls with DeepSeekMultiAgentFormatter.
The multi-agent formatter wraps prior conversation history in
<history></history> tags, enabling the model to handle multi-agent
conversations where more than one non-user agent is involved.
"""
import asyncio
import os
from ... | 103 | 2,897 |
agentscope | scripts/model_examples/xai_call.py | .py | # -*- coding: utf-8 -*-
"""Examples of xAI Grok model calls using the official xai_sdk gRPC client.
Unlike the OpenAI-compatible approach, the xai_sdk provides native access to
xAI-specific features such as server-side agentic tools (web search, X search,
code execution) and extended reasoning control.
"""
import asyn... | 196 | 5,551 |
agentscope | scripts/model_examples/anthropic_multiagent.py | .py | # -*- coding: utf-8 -*-
"""Example of Anthropic Claude model calls with AnthropicMultiAgentFormatter.
The multi-agent formatter wraps prior conversation history in
<history></history> tags, enabling the model to handle multi-agent
conversations where more than one non-user agent is involved.
"""
import asyncio
import ... | 106 | 2,967 |
agentscope | scripts/model_examples/deepseek_call.py | .py | # -*- coding: utf-8 -*-
"""Examples of DeepSeek model calls.
For DeepSeek, thinking (chain-of-thought) is controlled by the
``thinking_enable`` parameter on ``deepseek-v4-flash``. The legacy
``deepseek-chat`` / ``deepseek-reasoner`` model names will be deprecated;
they correspond to the non-thinking / thinking modes o... | 190 | 5,609 |
agentscope | scripts/model_examples/openai_response_multiagent.py | .py | # -*- coding: utf-8 -*-
"""Example of OpenAI Responses API model calls with
OpenAIResponseMultiAgentFormatter.
The multi-agent formatter wraps prior conversation history in
<history></history> tags, enabling the model to handle multi-agent
conversations where more than one non-user agent is involved.
"""
import asynci... | 103 | 2,850 |
agentscope | scripts/model_examples/run_tests.py | .py | # -*- coding: utf-8 -*-
"""Unified test runner for AgentScope model scripts.
Automatically reads API keys from environment variables and only runs tests
for providers whose keys are present. Supports fine-grained control over
which providers and test types to run.
Usage examples:
# Run all available tests (auto-d... | 586 | 17,924 |
agentscope | scripts/model_examples/anthropic_multimodal.py | .py | # -*- coding: utf-8 -*-
"""Example of Anthropic Claude model multimodal (vision) calls using
DataBlock."""
import asyncio
import base64
import os
from pathlib import Path
from _utils import stream_and_collect
from agentscope.message import (
Msg,
TextBlock,
DataBlock,
URLSource,
Base64Source,
)
fro... | 155 | 4,005 |
agentscope | scripts/model_examples/dashscope_multiagent.py | .py | # -*- coding: utf-8 -*-
"""Example of DashScope model calls with DashScopeMultiAgentFormatter.
The multi-agent formatter wraps prior conversation history in
<history></history> tags, enabling the model to handle multi-agent
conversations where more than one non-user agent is involved.
"""
import asyncio
import os
fro... | 102 | 2,893 |
agentscope | scripts/model_examples/openai_chat_multiagent_multimodal.py | .py | # -*- coding: utf-8 -*-
"""Example of OpenAI Chat model calls with MultiAgentFormatter and image
input."""
import asyncio
import os
from _utils import stream_and_collect
from agentscope.formatter import OpenAIMultiAgentFormatter
from agentscope.message import Msg, TextBlock, DataBlock, URLSource
from agentscope.model ... | 91 | 2,536 |
agentscope | scripts/model_examples/moonshot_multiagent.py | .py | # -*- coding: utf-8 -*-
"""Example of Moonshot model calls with MoonshotMultiAgentFormatter.
The multi-agent formatter wraps prior conversation history in
<history></history> tags and preserves reasoning_content for Moonshot's
Preserved Thinking feature in multi-turn conversations.
"""
import asyncio
import os
from _... | 102 | 2,874 |
agentscope | scripts/model_examples/openai_chat_multiagent.py | .py | # -*- coding: utf-8 -*-
"""Example of OpenAI Chat model calls with OpenAIMultiAgentFormatter.
The multi-agent formatter wraps prior conversation history in
<history></history> tags, enabling the model to handle multi-agent
conversations where more than one non-user agent is involved.
"""
import asyncio
import os
from... | 101 | 2,789 |
agentscope | scripts/model_examples/anthropic_call.py | .py | # -*- coding: utf-8 -*-
"""Examples of Anthropic Claude model calls."""
import asyncio
import json
import os
from pydantic import BaseModel, Field
from _utils import stream_and_collect
from agentscope.message import (
Msg,
TextBlock,
ToolCallBlock,
ToolResultBlock,
ToolResultState,
)
from agentsco... | 192 | 5,462 |
agentscope | scripts/model_examples/openai_chat_call.py | .py | # -*- coding: utf-8 -*-
"""Examples of OpenAI Chat Completions model calls."""
import asyncio
import json
import os
from pydantic import BaseModel, Field
from _utils import stream_and_collect
from agentscope.message import (
Msg,
TextBlock,
ToolCallBlock,
ToolResultBlock,
ToolResultState,
)
from a... | 192 | 5,408 |
agentscope | scripts/model_examples/xai_multimodal.py | .py | # -*- coding: utf-8 -*-
"""Example of Grok model multimodal (vision) calls using DataBlock.
Note: Vision (image) input is supported by grok-4.3 and above.
grok-3-mini does NOT support image input.
"""
import asyncio
import base64
import os
from pathlib import Path
from _utils import stream_and_collect
from agentscope... | 141 | 3,687 |
agentscope | scripts/model_examples/ollama_call.py | .py | # -*- coding: utf-8 -*-
"""Examples of Ollama (local) model calls.
Make sure Ollama is running locally before running these examples:
ollama serve
Pull the model first if you haven't already:
ollama pull qwen3:14b
"""
import asyncio
import json
from pydantic import BaseModel, Field
from _utils import stream... | 189 | 5,337 |
agentscope | scripts/model_examples/dashscope_multimodal.py | .py | # -*- coding: utf-8 -*-
"""Example of DashScope model multimodal (vision) calls using DataBlock."""
import asyncio
import base64
import os
from pathlib import Path
from _utils import stream_and_collect
from agentscope.message import (
Msg,
TextBlock,
DataBlock,
URLSource,
Base64Source,
)
from agent... | 232 | 5,956 |
agentscope | scripts/model_examples/dashscope_call.py | .py | # -*- coding: utf-8 -*-
"""Examples of DashScope (Alibaba) model calls."""
import asyncio
import json
import os
from pydantic import BaseModel, Field
from _utils import stream_and_collect
from agentscope.message import (
Msg,
ToolCallBlock,
ToolResultBlock,
ToolResultState,
TextBlock,
)
from agent... | 186 | 5,361 |
agentscope | scripts/model_examples/gemini_multiagent.py | .py | # -*- coding: utf-8 -*-
"""Example of Gemini model calls with GeminiMultiAgentFormatter.
The multi-agent formatter wraps prior conversation history in
<history></history> tags, enabling the model to handle multi-agent
conversations where more than one non-user agent is involved.
"""
import asyncio
import os
from _uti... | 106 | 2,932 |
agentscope | scripts/model_examples/ollama_multimodal.py | .py | # -*- coding: utf-8 -*-
"""Example of Ollama model multimodal (vision) calls using DataBlock.
Note: Vision input requires a multimodal Ollama model such as llava, bakllava,
or moondream. Run `ollama pull llava` before executing this example.
"""
import asyncio
import base64
from pathlib import Path
from _utils import... | 137 | 3,540 |
agentscope | scripts/model_examples/gemini_multimodal.py | .py | # -*- coding: utf-8 -*-
"""Example of Gemini model multimodal (vision) calls using DataBlock."""
import asyncio
import base64
import os
from pathlib import Path
from _utils import stream_and_collect
from agentscope.message import (
Msg,
TextBlock,
DataBlock,
URLSource,
Base64Source,
)
from agentsco... | 144 | 3,868 |
agentscope | scripts/model_examples/dashscope_multiagent_multimodal.py | .py | # -*- coding: utf-8 -*-
"""Example of DashScope model calls with MultiAgentFormatter and image input.
Demonstrates combining DashScopeMultiAgentFormatter with multimodal (vision)
content: Alice shares an image in a multi-agent conversation, and the model
is asked to summarize what everyone is looking at.
"""
import as... | 96 | 2,838 |
agentscope | examples/long_term_memory/agentic_memory/main.py | .py | # -*- coding: utf-8 -*-
"""AgenticMemoryMiddleware end-to-end demo.
The demo uses a single Agent with the filesystem-backed long-term memory
middleware and the built-in ``Read`` / ``Write`` tools across two turns:
1. The Agent receives mock user input that explicitly asks it to remember
durable user information. T... | 239 | 8,113 |
agentscope | examples/long_term_memory/reme/reme_demo.py | .py | # -*- coding: utf-8 -*-
"""ReMe middleware demo (embedded reme-ai, AgentScope-driven).
Drives two independent agent **sessions** that share one ReMe
workspace, so ReMe's cross-session memory effect is visible: session 1
states a durable preference, the middleware writes it back
automatically, and a *fresh* session-2 a... | 337 | 14,089 |
agentscope | examples/long_term_memory/mem0/oss_demo.py | .py | # -*- coding: utf-8 -*-
"""Mem0 middleware demo (open-source mem0, AgentScope-driven).
Drives two independent agent sessions for the same ``user_id`` so
mem0's cross-session memory effect is visible. Each turn streams
events from ``agent.reply_stream`` and prints the ones that matter:
- ``[mem0 → context (static)]`` ... | 337 | 13,149 |
agentscope | examples/agent_service/main.py | .py | # -*- coding: utf-8 -*-
"""The example script to start the agent service."""
import os
import uvicorn
from fastapi.middleware import Middleware
from fastapi.middleware.cors import CORSMiddleware
from agentscope.app import create_app, SubAgentTemplate
from agentscope.app.channel import DiscordChannel, FeishuChannel
fr... | 167 | 5,577 |
agentscope | examples/rag/integrate_with_agent.py | .py | # -*- coding: utf-8 -*-
"""Wire :class:`RAGMiddleware` into an :class:`Agent` — library mode.
The middleware in :mod:`agentscope.middleware._rag` is the agent-side
half of RAG: given one or more :class:`~agentscope.rag.KnowledgeBase`
handles (each pairing an embedding model with a vector-store
collection), the middlew... | 199 | 7,023 |
agentscope | examples/rag/index_and_search.py | .py | # -*- coding: utf-8 -*-
"""Library-mode RAG walk-through — no FastAPI service, no manager.
End-to-end demo of the building blocks in :mod:`agentscope.rag`:
1. **Vector store** — :class:`QdrantStore` (in-memory here; swap to
``url=...`` for a real Qdrant server).
2. **Parser** — :class:`TextParser` turning raw byte... | 184 | 6,496 |
agentscope | examples/console/main.py | .py | # -*- coding: utf-8 -*-
"""Try a full-featured agent in the terminal via ``launch_console``.
The agent is backed by ``DashScopeChatModel`` and assembled from a
``LocalWorkspace``: the builtin filesystem tools and the agent skills
both come from the workspace, and the filesystem-backed long-term
memory (``AgenticMemory... | 89 | 3,125 |
agentscope | src/agentscope/_version.py | .py | # -*- coding: utf-8 -*-
"""The version of agentscope."""
__version__ = "2.0.6"
| 5 | 80 |
agentscope | src/agentscope/__init__.py | .py | # -*- coding: utf-8 -*-
"""The agentscope serialization module"""
import warnings
from ._logging import (
logger,
setup_logger,
)
from ._utils._common import set_id_factory, set_timestamp_factory
from ._version import __version__
# Raise each warning only once
warnings.filterwarnings("once", category=Deprecat... | 23 | 452 |
agentscope | src/agentscope/_logging.py | .py | # -*- coding: utf-8 -*-
"""The logger for agentscope."""
import logging
_DEFAULT_FORMAT = (
"%(asctime)s | %(levelname)-7s | "
"%(module)s:%(funcName)s:%(lineno)s - %(message)s"
)
logger = logging.getLogger("as")
def setup_logger(
level: str,
filepath: str | None = None,
) -> None:
"""Set up t... | 48 | 1,223 |
agentscope | src/agentscope/skill/_base.py | .py | # -*- coding: utf-8 -*-
"""The skill loader base class."""
from abc import abstractmethod, ABC
from dataclasses import dataclass
@dataclass
class Skill:
"""The agent skill class"""
name: str
"""The name of the skill."""
description: str
"""The description of the skill."""
dir: str
"""The ... | 30 | 735 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.