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 | src/agentscope/skill/_local_loader.py | .py | # -*- coding: utf-8 -*-
"""The local skill loader class."""
import asyncio
import os
import aiofiles
import aiofiles.ospath
import frontmatter
from ._base import SkillLoaderBase
from .._logging import logger
from .._utils._common import _normalize_local_path
from ..skill import Skill
class LocalSkillLoader(SkillLoa... | 173 | 5,609 |
agentscope | src/agentscope/skill/__init__.py | .py | # -*- coding: utf-8 -*-
"""The skill related classes and functions."""
from ._base import SkillLoaderBase, Skill
from ._local_loader import LocalSkillLoader
__all__ = [
"Skill",
"SkillLoaderBase",
"LocalSkillLoader",
]
| 12 | 233 |
agentscope | src/agentscope/workspace/_local_workspace.py | .py | # -*- coding: utf-8 -*-
"""The local workspace class."""
import asyncio
import hashlib
import json
import os
import re
import shutil
import sys
from typing import AsyncIterator, Literal, TypedDict
import frontmatter
from ._utils import DEFAULT_WORKSPACE_INSTRUCTIONS
from .._logging import logger
from .._utils._commo... | 995 | 35,491 |
agentscope | src/agentscope/workspace/_gateway_client.py | .py | # -*- coding: utf-8 -*-
"""Host-side client for the in-sandbox MCP gateway, driven through
``backend.exec_shell``.
Three classes:
* :class:`GatewayClient` β workspace-side facade over ``/health`` and
``/mcps``. Used by the sandboxed workspaces for top-level operations.
* :class:`GatewayMCPClient` β an :class:`MCPCl... | 789 | 29,932 |
agentscope | src/agentscope/workspace/_utils.py | .py | # -*- coding: utf-8 -*-
"""Host-side helpers shared by workspace implementations.
Constants for the standard workspace layout, plus pure functions for
detecting the local ``agentscope`` version and reading scripts bundled
with the package. No Docker / E2B SDK dependency lives here.
This module is internal to ``agents... | 153 | 6,323 |
agentscope | src/agentscope/workspace/_offload_protocol.py | .py | # -*- coding: utf-8 -*-
"""The offload protocol."""
from typing import Protocol
from ..message import DataBlock, Msg, ToolResultBlock
class Offloader(Protocol):
"""The offloader protocol."""
async def offload_data_block(self, block: DataBlock) -> DataBlock:
"""Persist a base64 data block to workspac... | 60 | 1,567 |
agentscope | src/agentscope/workspace/_base.py | .py | # -*- coding: utf-8 -*-
# pylint: disable=too-many-lines
"""WorkspaceBase β abstract interface and shared backend-driven impl.
A workspace provides:
- **Resources** β skills available to the agent.
- **Tools** β MCPs and built-in tools for operating on resources.
- **Offload** β persistence of compressed context and ... | 1,582 | 59,475 |
agentscope | src/agentscope/workspace/__init__.py | .py | # -*- coding: utf-8 -*-
"""The workspace module in agentscope."""
from ._base import WorkspaceBase
from ._local_workspace import LocalWorkspace
from ._offload_protocol import Offloader
from ._docker import DockerBackend, DockerWorkspace
from ._e2b import E2BWorkspace, E2BBackend
from ._daytona import DaytonaBackend, ... | 36 | 995 |
agentscope | src/agentscope/workspace/_gateway_shim.py | .py | # -*- coding: utf-8 -*-
"""Tiny Python script that runs inside the sandbox to relay a single
HTTP request to the gateway, plus the host-side constants that drive it
through :meth:`BackendBase.exec_shell`.
Flow: host spawns ``python3 -c <SHIM_SCRIPT> ...`` via ``exec_shell``;
the shim calls the gateway's loopback port ... | 97 | 3,260 |
agentscope | src/agentscope/workspace/_sandboxed_base.py | .py | # -*- coding: utf-8 -*-
"""SandboxedWorkspaceBase β shared implementation for gateway-backed
sandbox workspaces (Docker, E2B, K8s, β¦).
Extends :class:`WorkspaceBase` with a template-method lifecycle around
an in-sandbox MCP gateway. Subclasses only need to provide:
- :meth:`_provision_backend` β attach/create the san... | 529 | 19,591 |
agentscope | src/agentscope/workspace/_k8s/_constants.py | .py | # -*- coding: utf-8 -*-
"""K8s-specific constants for :class:`K8sWorkspace`.
Path layout (venv, script, log, helper) is derived on the base class
from ``_gateway_home``. This module only carries defaults that cannot
be derived: image, port, apt deps, workdir/gateway_home, and the
K8s-name sanitiser.
"""
import re
#:... | 43 | 1,514 |
agentscope | src/agentscope/workspace/_k8s/__init__.py | .py | # -*- coding: utf-8 -*-
"""Kubernetes-backed workspace package.
Re-exports :class:`K8sWorkspace` and :class:`K8sBackend` so callers
can write ``from agentscope.workspace._k8s import K8sWorkspace``
without having to poke at the underlying module layout.
"""
from ._k8s_workspace import K8sWorkspace
from ._k8s_backend i... | 13 | 379 |
agentscope | src/agentscope/workspace/_k8s/_k8s_workspace.py | .py | # -*- coding: utf-8 -*-
"""K8sWorkspace β sandboxed workspace backed by a Kubernetes Pod.
Architecture
------------
Mirrors :class:`agentscope.workspace.DockerWorkspace` but swaps the
Docker engine for the Kubernetes API (``kubernetes_asyncio``):
* **Lifecycle.** ``initialize()`` looks up an existing Pod by label,
... | 616 | 23,762 |
agentscope | src/agentscope/workspace/_k8s/_k8s_backend.py | .py | # -*- coding: utf-8 -*-
"""Kubernetes Pod :class:`BackendBase` implementation.
Wraps the ``kubernetes_asyncio`` exec API and tar-stream file transfer
into the three backend primitives (``exec_shell``, ``read_file``,
``write_file``) so that builtin tools (Bash, Read, Write, Edit, Grep,
Glob) can operate inside a K8s Po... | 411 | 14,682 |
agentscope | src/agentscope/workspace/_opensandbox/_constants.py | .py | # -*- coding: utf-8 -*-
"""Constants for :class:`OpenSandboxWorkspace`, mirroring the E2B and
K8s ``_constants`` modules.
Only defaults that cannot be derived on the base class live here:
image, timeouts, gateway port, sandbox metadata key, plus the two
sandbox-side anchors the workspace must set (``SANDBOX_WORKDIR`` ... | 47 | 1,946 |
agentscope | src/agentscope/workspace/_opensandbox/__init__.py | .py | # -*- coding: utf-8 -*-
"""OpenSandbox-backed workspace.
OpenSandbox support follows the E2B remote-sandbox model: one sandbox
per workspace id, filesystem persistence inside the sandbox, and MCPs
reached through the in-sandbox gateway.
"""
from ._opensandbox_backend import OpenSandboxBackend
from ._opensandbox_works... | 13 | 411 |
agentscope | src/agentscope/workspace/_opensandbox/_opensandbox_workspace.py | .py | # -*- coding: utf-8 -*-
"""OpenSandboxWorkspace -- sandboxed workspace backed by OpenSandbox."""
from __future__ import annotations
import asyncio
from datetime import timedelta
import shlex
from typing import TYPE_CHECKING, Literal
from ..._logging import logger
from ...mcp import MCPClient
from .._sandboxed_base i... | 393 | 16,236 |
agentscope | src/agentscope/workspace/_opensandbox/_opensandbox_backend.py | .py | # -*- coding: utf-8 -*-
"""OpenSandbox :class:`BackendBase` implementation.
Wraps the OpenSandbox SDK's ``commands.run`` and ``files.*`` APIs into
the three backend primitives (``exec_shell``, ``read_file``,
``write_file``) so builtin tools can operate inside an OpenSandbox
sandbox transparently. All derived filesyst... | 278 | 9,827 |
agentscope | src/agentscope/workspace/_applecontainer/_constants.py | .py | # -*- coding: utf-8 -*-
"""Apple-Container-specific constants for
:class:`AppleContainerWorkspace`.
Path layout (venv, script, log, helper) is derived on the base class
from ``_gateway_home``. This module only carries defaults that cannot
be derived: image, timeouts, port, container user, workdir.
"""
#: Default base... | 28 | 887 |
agentscope | src/agentscope/workspace/_applecontainer/__init__.py | .py | # -*- coding: utf-8 -*-
"""Apple-Container-backed workspace.
Uses Apple's ``container`` CLI to run Linux containers as lightweight
VMs on macOS 26+ with Apple silicon. MCP servers run *inside* the
container behind a FastAPI gateway and are reached through
:class:`GatewayClient` via :class:`AppleContainerBackend`.
Req... | 19 | 616 |
agentscope | src/agentscope/workspace/_applecontainer/_applecontainer_workspace.py | .py | # -*- coding: utf-8 -*-
"""AppleContainerWorkspace β sandboxed workspace backed by Apple's
``container`` CLI.
Architecture
------------
Mirrors :class:`agentscope.workspace.E2BWorkspace` but swaps the E2B
SDK for the ``container`` CLI:
* **Lifecycle.** ``initialize()`` pulls the base image (if needed),
creates and... | 526 | 19,734 |
agentscope | src/agentscope/workspace/_applecontainer/_applecontainer_backend.py | .py | # -*- coding: utf-8 -*-
"""Apple Container :class:`BackendBase` implementation.
Wraps the ``container`` CLI (``container exec``, ``container cp``)
into the three backend primitives (``exec_shell``, ``read_file``,
``write_file``) so that builtin tools (Bash, Read, Write, Edit, Grep,
Glob) can operate inside an Apple co... | 216 | 7,288 |
agentscope | src/agentscope/workspace/_mcp_gateway/_mcp_gateway_app.py | .py | # -*- coding: utf-8 -*-
"""In-workspace MCP gateway β FastAPI router over agentscope MCPClients.
Runs inside the workspace environment as a standalone script. It starts
with an empty registry and never reads the workspace's ``.mcp`` file:
the workspace is the authority on which MCPs exist, and registers them
here on d... | 245 | 7,935 |
agentscope | src/agentscope/workspace/_mcp_gateway/__main__.py | .py | # -*- coding: utf-8 -*-
"""``python -m agentscope.workspace._mcp_gateway`` entry point.
Inside the workspace container the gateway is launched as::
python -m agentscope.workspace._mcp_gateway --config <path> --port <port>
so this module simply forwards to :func:`_mcp_gateway_app.main`.
"""
from ._mcp_gateway_ap... | 15 | 373 |
agentscope | src/agentscope/workspace/_mcp_gateway/__init__.py | .py | # -*- coding: utf-8 -*-
"""In-workspace MCP gateway package.
The gateway is a single self-contained script that runs *inside* the
workspace environment (Docker / E2B). It is copied into the container
at image build time and executed by the workspace at startup.
The script must remain importable without ``agentscope``... | 12 | 433 |
agentscope | src/agentscope/workspace/_e2b/_constants.py | .py | # -*- coding: utf-8 -*-
"""E2B-specific constants for :class:`E2BWorkspace`.
Path layout (venv, script, log, helper) is derived on the base class
from ``_gateway_home``. This module only carries defaults that cannot
be derived: template, timeouts, port, sandbox user, metadata key.
"""
#: Default E2B template. Matches... | 29 | 1,062 |
agentscope | src/agentscope/workspace/_e2b/__init__.py | .py | # -*- coding: utf-8 -*-
"""E2B-backed workspace package.
Re-exports :class:`E2BWorkspace` so callers can write
``from agentscope.workspace._e2b import E2BWorkspace`` without having to
poke at the underlying module layout.
"""
from ._e2b_workspace import E2BWorkspace
from ._e2b_backend import E2BBackend
__all__ = ["E... | 13 | 348 |
agentscope | src/agentscope/workspace/_e2b/_e2b_backend.py | .py | # -*- coding: utf-8 -*-
"""E2B sandbox :class:`BackendBase` implementation.
Wraps the E2B SDK's ``commands.run`` and ``files.*`` APIs into the
three backend primitives (``exec_shell``, ``read_file``,
``write_file``) so that builtin tools (Bash, Read, Write, Edit, Grep,
Glob) can operate inside an E2B cloud sandbox tra... | 164 | 5,852 |
agentscope | src/agentscope/workspace/_e2b/_e2b_workspace.py | .py | # -*- coding: utf-8 -*-
"""E2BWorkspace β sandboxed workspace backed by an E2B cloud sandbox.
Architecture
------------
Mirrors :class:`agentscope.workspace.DockerWorkspace` but swaps the
Docker engine for the E2B SDK (``e2b.AsyncSandbox``):
* **Lifecycle.** ``initialize()`` looks up an existing sandbox by
metadat... | 363 | 15,501 |
agentscope | src/agentscope/workspace/_bubblewrap/_constants.py | .py | # -*- coding: utf-8 -*-
"""Constants for Bubblewrap-backed workspaces."""
DEFAULT_GATEWAY_PORT = None
SANDBOX_WORKDIR = "/workspace"
SANDBOX_TMPDIR = "/tmp"
SANDBOX_CACHE_DIR = f"{SANDBOX_TMPDIR}/.agentscope-cache"
GATEWAY_HOME = f"{SANDBOX_WORKDIR}/.agentscope"
BWRAP_SMOKE_PROBE_ARGV = [
"bwrap",
"--die-wit... | 27 | 503 |
agentscope | src/agentscope/workspace/_bubblewrap/__init__.py | .py | # -*- coding: utf-8 -*-
"""Bubblewrap-backed workspace."""
from ._bubblewrap_backend import BubblewrapBackend
from ._bubblewrap_workspace import BubblewrapWorkspace
__all__ = ["BubblewrapBackend", "BubblewrapWorkspace"]
| 8 | 222 |
agentscope | src/agentscope/workspace/_bubblewrap/_bubblewrap_backend.py | .py | # -*- coding: utf-8 -*-
"""Bubblewrap :class:`BackendBase` implementation.
The backend launches each command through ``bwrap`` with a stable host
directory mounted at ``/workspace`` and a stable host temp directory
mounted at ``/tmp``. Those two writable mounts are enough for the shared
workspace implementation, gate... | 604 | 21,462 |
agentscope | src/agentscope/workspace/_bubblewrap/_bubblewrap_workspace.py | .py | # -*- coding: utf-8 -*-
# pylint: disable=protected-access,consider-using-with
"""BubblewrapWorkspace -- sandboxed workspace backed by ``bwrap``."""
from __future__ import annotations
import asyncio
import hashlib
import os
import secrets
import shlex
import shutil
import socket
import sys
import tempfile
from typing... | 658 | 26,156 |
agentscope | src/agentscope/workspace/_docker/_docker_workspace.py | .py | # -*- coding: utf-8 -*-
"""DockerWorkspace β sandboxed workspace backed by a Docker container.
* Container lifecycle (build + run + stop) via **aiodocker**.
* MCP servers run inside the container behind a FastAPI gateway
(see :mod:`agentscope.workspace._mcp_gateway`); the host reaches it
through :class:`GatewayCli... | 322 | 13,306 |
agentscope | src/agentscope/workspace/_docker/__init__.py | .py | # -*- coding: utf-8 -*-
"""Docker-backed workspace.
The container image is built on demand from a content-hashed Dockerfile
(see :mod:`._make_dockerfile`); a tag cache hit skips the build. MCP
servers run *inside* the container behind a FastAPI gateway and are
reached over HTTP β see :mod:`agentscope.workspace._gatewa... | 14 | 476 |
agentscope | src/agentscope/workspace/_docker/_docker_backend.py | .py | # -*- coding: utf-8 -*-
"""Docker container :class:`BackendBase` implementation.
Wraps the ``aiodocker`` container APIs (``exec``, ``get_archive``,
``put_archive``) into the three backend primitives (``exec_shell``,
``read_file``, ``write_file``) so that builtin tools (Bash, Read,
Write, Edit, Grep, Glob) can operate ... | 194 | 6,709 |
agentscope | src/agentscope/workspace/_docker/_make_dockerfile.py | .py | # -*- coding: utf-8 -*-
"""Dockerfile generation + build-context preparation for DockerWorkspace.
The image is keyed by content hash of the Dockerfile text plus all
files COPYed into it. If the tag already exists locally the build is
skipped; otherwise the caller builds with the prepared context.
The container instal... | 197 | 7,279 |
agentscope | src/agentscope/workspace/_daytona/_constants.py | .py | # -*- coding: utf-8 -*-
"""Constants for :class:`DaytonaWorkspace`, mirroring the E2B and K8s
``_constants`` modules.
Only defaults that cannot be derived on the shared sandbox base live
here: SDK operation timeout, gateway port, sweeper interval, the
sandbox label key used for reattachment, and the gateway home ancho... | 33 | 1,357 |
agentscope | src/agentscope/workspace/_daytona/__init__.py | .py | # -*- coding: utf-8 -*-
"""Daytona-backed workspace package.
Re-exports :class:`DaytonaWorkspace` so callers can write
``from agentscope.workspace._daytona import DaytonaWorkspace`` without
having to poke at the underlying module layout.
"""
from ._daytona_backend import DaytonaBackend
from ._daytona_workspace import... | 16 | 399 |
agentscope | src/agentscope/workspace/_daytona/_daytona_workspace.py | .py | # -*- coding: utf-8 -*-
"""DaytonaWorkspace β sandboxed workspace backed by Daytona.
Architecture
------------
Mirrors :class:`agentscope.workspace.E2BWorkspace` and
:class:`agentscope.workspace.DockerWorkspace` at the AgentScope
boundary, but swaps the provider runtime for the Daytona SDK:
* **Lifecycle.** ``initia... | 493 | 20,746 |
agentscope | src/agentscope/workspace/_daytona/_daytona_backend.py | .py | # -*- coding: utf-8 -*-
"""Daytona sandbox :class:`BackendBase` implementation.
Wraps Daytona SDK ``process.exec`` and ``fs.*`` APIs into the three
backend primitives (``exec_shell``, ``read_file``, ``write_file``) so
that builtin tools (Bash, Read, Write, Edit, Grep, Glob) can operate
inside a Daytona sandbox transpa... | 168 | 6,121 |
agentscope | src/agentscope/message/_base.py | .py | # -*- coding: utf-8 -*-
"""The message class in agentscope."""
import base64
from datetime import datetime
from typing import Literal, List, overload, Sequence, Self, TYPE_CHECKING, Any
from pydantic import BaseModel, Field, model_validator
from .._utils._common import _generate_id
from ._block import (
TextBlock... | 665 | 25,501 |
agentscope | src/agentscope/message/_block.py | .py | # -*- coding: utf-8 -*-
"""The content blocks of messages."""
from enum import StrEnum
from typing import Literal, List, TypeAlias, Any
from pydantic import BaseModel, Field, AnyUrl, field_serializer, ConfigDict
from .._utils._common import _generate_id, _generate_timestamp
from ..permission import PermissionRule
cl... | 236 | 8,418 |
agentscope | src/agentscope/message/__init__.py | .py | # -*- coding: utf-8 -*-
"""The message module in agentscope."""
from ._block import (
ContentBlock,
ContentBlockTypes,
TextBlock,
ThinkingBlock,
HintBlock,
ToolCallBlock,
ToolCallState,
ToolResultBlock,
ToolResultState,
DataBlock,
Base64Source,
URLSource,
)
from ._base i... | 40 | 705 |
agentscope | src/agentscope/event/_event.py | .py | # -*- coding: utf-8 -*-
"""Event types for agent execution."""
from datetime import datetime
from enum import StrEnum
from typing import Any, Dict, Literal, List, TypeAlias
from pydantic import BaseModel, Field, ConfigDict
from typing_extensions import deprecated
from .._utils._common import _generate_id
from ..messa... | 569 | 17,664 |
agentscope | src/agentscope/event/__init__.py | .py | # -*- coding: utf-8 -*-
"""The event module of agentscope."""
from ..types import ReplyFinishedReason
from ._event import (
EventType,
EventBase,
ReplyStartEvent,
ReplyEndReason,
ReplyEndEvent,
ModelCallStartEvent,
ModelCallEndEvent,
TextBlockStartEvent,
TextBlockDeltaEvent,
Tex... | 78 | 1,828 |
agentscope | src/agentscope/credential/_openai.py | .py | # -*- coding: utf-8 -*-
"""The OpenAI credential."""
from typing import Literal, Type, TYPE_CHECKING
from pydantic import ConfigDict, Field, SecretStr
from ._base import CredentialBase
if TYPE_CHECKING:
from ..embedding import EmbeddingModelBase
from ..model import ChatModelBase
from ..tts import TTSMode... | 65 | 1,731 |
agentscope | src/agentscope/credential/_moonshot.py | .py | # -*- coding: utf-8 -*-
"""The Moonshot AI credential."""
from typing import Literal, Type, TYPE_CHECKING
from pydantic import ConfigDict, Field, SecretStr
from ._base import CredentialBase
if TYPE_CHECKING:
from ..model import ChatModelBase
_MOONSHOT_BASE_URL = "https://api.moonshot.cn/v1"
class MoonshotCred... | 42 | 1,050 |
agentscope | src/agentscope/credential/_deepseek.py | .py | # -*- coding: utf-8 -*-
"""The DeepSeek credential."""
from typing import Literal, Type, TYPE_CHECKING
from pydantic import ConfigDict, Field, SecretStr
from ._base import CredentialBase
if TYPE_CHECKING:
from ..model import ChatModelBase
_DEEPSEEK_BASE_URL = "https://api.deepseek.com"
class DeepSeekCredentia... | 42 | 1,033 |
agentscope | src/agentscope/credential/_base.py | .py | # -*- coding: utf-8 -*-
"""The credential base class."""
from typing import TYPE_CHECKING, Type
from pydantic import BaseModel, Field
from .._utils._common import _generate_id
if TYPE_CHECKING:
from ..embedding import EmbeddingModelBase
from ..model import ChatModelBase, ModelCard
from ..tts import TTSMo... | 97 | 3,179 |
agentscope | src/agentscope/credential/_ollama.py | .py | # -*- coding: utf-8 -*-
"""The Ollama credential."""
from typing import Literal, Type, TYPE_CHECKING
from pydantic import ConfigDict, Field
from ._base import CredentialBase
if TYPE_CHECKING:
from ..embedding import EmbeddingModelBase
from ..model import ChatModelBase
class OllamaCredential(CredentialBase)... | 46 | 1,215 |
agentscope | src/agentscope/credential/__init__.py | .py | # -*- coding: utf-8 -*-
"""The credential module."""
from ._base import CredentialBase
from ._anthropic import AnthropicCredential
from ._dashscope import DashScopeCredential
from ._deepseek import DeepSeekCredential
from ._gemini import GeminiCredential
from ._moonshot import MoonshotCredential
from ._ollama import O... | 28 | 708 |
agentscope | src/agentscope/credential/_factory.py | .py | # -*- coding: utf-8 -*-
"""The credential factory class."""
from typing import Annotated, Type, Union, get_args, get_type_hints
from pydantic import TypeAdapter, Field
from ._anthropic import AnthropicCredential
from ._dashscope import DashScopeCredential
from ._deepseek import DeepSeekCredential
from ._gemini import... | 117 | 3,641 |
agentscope | src/agentscope/credential/_anthropic.py | .py | # -*- coding: utf-8 -*-
"""The Anthropic credential."""
from typing import Literal, Type, TYPE_CHECKING
from pydantic import Field, SecretStr, ConfigDict
from ._base import CredentialBase
if TYPE_CHECKING:
from ..model import ChatModelBase
class AnthropicCredential(CredentialBase):
"""The Anthropic credent... | 40 | 988 |
agentscope | src/agentscope/credential/_dashscope.py | .py | # -*- coding: utf-8 -*-
"""The DashScope credential."""
from typing import Literal, Type, TYPE_CHECKING
from pydantic import ConfigDict, Field, SecretStr
from ._base import CredentialBase
if TYPE_CHECKING:
from ..embedding import EmbeddingModelBase
from ..model import ChatModelBase
from ..tts import TTSM... | 68 | 1,864 |
agentscope | src/agentscope/credential/_gemini.py | .py | # -*- coding: utf-8 -*-
"""The Google Gemini credential."""
from typing import Literal, Type, TYPE_CHECKING
from pydantic import ConfigDict, Field, SecretStr
from ._base import CredentialBase
if TYPE_CHECKING:
from ..embedding import EmbeddingModelBase
from ..model import ChatModelBase
from ..tts import ... | 50 | 1,334 |
agentscope | src/agentscope/credential/_xai.py | .py | # -*- coding: utf-8 -*-
"""The xAI credential."""
from typing import Literal, Type, TYPE_CHECKING
from pydantic import ConfigDict, Field, SecretStr
from ._base import CredentialBase
if TYPE_CHECKING:
from ..model import ChatModelBase
class XAICredential(CredentialBase):
"""The xAI credential model."""
... | 44 | 1,034 |
agentscope | src/agentscope/state/_state.py | .py | # -*- coding: utf-8 -*-
"""The agent state class."""
from typing import Any, Type
from pydantic import BaseModel, Field, field_serializer, model_validator
import aiofiles.os
from .._utils._common import _generate_id
from ._task import Task
from ..message import (
TextBlock,
DataBlock,
Msg,
ToolCallBl... | 371 | 13,162 |
agentscope | src/agentscope/state/_task.py | .py | # -*- coding: utf-8 -*-
"""The task class."""
from datetime import datetime
from typing import Any, Literal
from pydantic import BaseModel, Field
from .._utils._common import _generate_id
class Task(BaseModel):
"""The agent task."""
subject: str
"""The subject of the task."""
description: str
... | 40 | 991 |
agentscope | src/agentscope/state/__init__.py | .py | # -*- coding: utf-8 -*-
"""The agent state module in agentscope."""
from ._state import AgentState, TaskContext, ReplyContext, ToolContext
from ._task import Task
__all__ = [
"Task",
"TaskContext",
"ReplyContext",
"ToolContext",
"AgentState",
]
| 14 | 267 |
agentscope | src/agentscope/rag/__init__.py | .py | # -*- coding: utf-8 -*-
"""The retrieval-augmented generation (RAG) module in AgentScope."""
from ._chunker import ApproxTokenChunker, ChunkerBase
from ._document import (
Section,
Chunk,
)
from ._parser import (
ImageParser,
ParserBase,
PDFParser,
PPTParser,
TextParser,
WordParser,
... | 52 | 975 |
agentscope | src/agentscope/rag/_document.py | .py | # -*- coding: utf-8 -*-
"""Data structures used in the RAG indexing pipeline.
The indexing pipeline has two stages, each producing its own
structured output:
1. :class:`Section` β produced by a :class:`ParserBase` from a raw
file. Each ``Section`` represents one "natural boundary" of the
source (a PDF page, a ... | 103 | 3,876 |
agentscope | src/agentscope/rag/_knowledge.py | .py | # -*- coding: utf-8 -*-
"""Runtime handle for a single knowledge base.
A :class:`KnowledgeBase` instance is the **single algorithmic source of
truth** for talking to one knowledge base: it pairs an embedding model
with a vector-store collection (optionally scoped by a payload
``metadata_filter``) and exposes the four ... | 385 | 15,374 |
agentscope | src/agentscope/rag/_vdb/_elasticsearch.py | .py | # -*- coding: utf-8 -*-
"""Elasticsearch implementation of the vector store backend."""
from __future__ import annotations
import hashlib
from typing import TYPE_CHECKING, Any, Literal
from .._document import Chunk
from ._vector_store import (
DocumentSummary,
VectorRecord,
VectorSearchResult,
VectorS... | 298 | 10,576 |
agentscope | src/agentscope/rag/_vdb/__init__.py | .py | # -*- coding: utf-8 -*-
"""The vector store classes in AgentScope."""
from ._vector_store import (
DocumentSummary,
VectorRecord,
VectorSearchResult,
VectorStoreBase,
)
from ._qdrant import QdrantStore
from ._mongodb import MongoDBStore
from ._milvus_lite import MilvusLiteStore
from ._elasticsearch imp... | 25 | 538 |
agentscope | src/agentscope/rag/_vdb/_vector_store.py | .py | # -*- coding: utf-8 -*-
"""Abstract base class for vector store backends.
A :class:`VectorStoreBase` instance is the single connection point to
one vector database deployment. It is created once at application
startup, passed into ``create_app(vector_store=...)``, and shared
across all requests for the lifetime of th... | 292 | 10,199 |
agentscope | src/agentscope/rag/_vdb/_milvus_lite.py | .py | # -*- coding: utf-8 -*-
"""Milvus Lite implementation of the vector store backend.
Built on the official ``pymilvus`` ``MilvusClient`` API. Milvus Lite is
started automatically when the URI points to a local ``.db`` file, so it
is convenient for local development, tests, and small RAG workloads.
"""
import asyncio
imp... | 457 | 15,604 |
agentscope | src/agentscope/rag/_vdb/_qdrant.py | .py | # -*- coding: utf-8 -*-
"""Qdrant implementation of the vector store backend.
Built on the official ``qdrant-client`` SDK using its fully
asynchronous client (:class:`~qdrant_client.AsyncQdrantClient`), so all
operations are non-blocking and safe to call from the application's
event loop.
The same class supports all ... | 393 | 13,230 |
agentscope | src/agentscope/rag/_vdb/_mongodb.py | .py | # -*- coding: utf-8 -*-
"""MongoDB implementation of the vector store backend.
Built on ``pymongo.AsyncMongoClient`` and MongoDB Vector Search
(``$vectorSearch``), so all operations are non-blocking and safe to
call from the application's event loop.
The same class supports MongoDB Atlas and self-hosted deployments
t... | 465 | 15,907 |
agentscope | src/agentscope/rag/_chunker/_approx_token_chunker.py | .py | # -*- coding: utf-8 -*-
"""A chunker that splits text by an approximate token count.
The token count is approximated as ``len(text.encode("utf-8")) // 4``,
which avoids a hard dependency on any tokenizer library while staying
within the right order of magnitude for most LLM tokenizers.
"""
from bisect import bisect_ri... | 173 | 5,805 |
agentscope | src/agentscope/rag/_chunker/_base.py | .py | # -*- coding: utf-8 -*-
"""Abstract base class for chunkers.
A :class:`ChunkerBase` subclass takes the :class:`Section` list
produced by a :class:`~agentscope.rag.ParserBase` and splits the
content into final :class:`Chunk` objects suitable for embedding and
storage in a vector database.
Chunkers are **format-agnosti... | 63 | 2,540 |
agentscope | src/agentscope/rag/_chunker/__init__.py | .py | # -*- coding: utf-8 -*-
"""Chunker implementations for the RAG indexing pipeline."""
from ._approx_token_chunker import ApproxTokenChunker
from ._base import ChunkerBase
__all__ = [
"ApproxTokenChunker",
"ChunkerBase",
]
| 11 | 231 |
agentscope | src/agentscope/rag/_parser/_utils.py | .py | # -*- coding: utf-8 -*-
"""Shared helpers for binary parsers.
Three small utilities used by :class:`PDFParser`, :class:`ImageParser`,
and :class:`PPTParser`:
- :func:`_guess_image_media_type` β sniff the IANA media type from raw
image bytes by looking at the magic number. Used to populate the
``media_type`` fiel... | 100 | 3,273 |
agentscope | src/agentscope/rag/_parser/_base.py | .py | # -*- coding: utf-8 -*-
"""Abstract base class for file parsers.
A :class:`ParserBase` subclass handles **one file format**. Its job
is to read a file's raw bytes and produce a list of
:class:`~agentscope.rag.Section` objects, each representing a natural
boundary of the source (e.g. one PDF page, one PPTX slide, one
... | 117 | 4,804 |
agentscope | src/agentscope/rag/_parser/__init__.py | .py | # -*- coding: utf-8 -*-
"""File parser implementations for the RAG indexing pipeline."""
from ._base import ParserBase
from ._image import ImageParser
from ._pdf import PDFParser
from ._ppt import PPTParser
from ._text import TextParser
from ._word import WordParser
from ._excel import ExcelParser
__all__ = [
"Pa... | 21 | 441 |
agentscope | src/agentscope/rag/_parser/_word.py | .py | # -*- coding: utf-8 -*-
# pylint: disable=protected-access
"""Word (.docx) file parser.
Walks the document element-by-element and emits one :class:`Section`
per contiguous content block β adjacent paragraphs (and, by default,
tables) are merged into a single text section; embedded images are
emitted as their own :clas... | 342 | 12,145 |
agentscope | src/agentscope/rag/_parser/_text.py | .py | # -*- coding: utf-8 -*-
"""Plain-text file parser."""
import os
from ...message import TextBlock
from .._document import Section
from ._base import ParserBase
class TextParser(ParserBase):
"""Parser for plain-text file formats.
Reads the entire file as UTF-8 text and returns a single
:class:`Section`. ... | 126 | 3,973 |
agentscope | src/agentscope/rag/_parser/_image.py | .py | # -*- coding: utf-8 -*-
"""Image file parser.
A single :class:`Section` carrying the raw image bytes as a
base64-encoded :class:`DataBlock`. No OCR, no captioning β the
section is the image, ready to flow through to a multimodal
embedding model unchanged.
"""
import base64
from ...message import Base64Source, DataBl... | 93 | 2,690 |
agentscope | src/agentscope/rag/_parser/_excel.py | .py | # -*- coding: utf-8 -*-
# pylint: disable=protected-access
"""Excel (.xlsx / .xls) file parser.
Reads an Excel workbook sheet-by-sheet and emits :class:`Section`
objects. Each sheet's tabular content is rendered as a single text
section (in Markdown or JSON format); embedded images (when enabled)
are emitted as their... | 463 | 15,693 |
agentscope | src/agentscope/rag/_parser/_pdf.py | .py | # -*- coding: utf-8 -*-
"""PDF file parser.
One :class:`Section` per page so a downstream
:class:`~agentscope.rag.ChunkerBase` never combines text across page
boundaries. Each section's :attr:`Section.metadata` carries the
page number (starting at 1) for later citation.
"""
import io
from ...message import TextBlock... | 93 | 2,988 |
agentscope | src/agentscope/rag/_parser/_ppt.py | .py | # -*- coding: utf-8 -*-
"""PowerPoint (.pptx) file parser.
Walks the deck slide-by-slide and emits one :class:`Section` per
contiguous content block β adjacent text runs (and, by default,
tables) are merged into a single text section; embedded images are
emitted as their own :class:`DataBlock` sections. Each section'... | 342 | 12,522 |
agentscope | src/agentscope/exception/_base.py | .py | # -*- coding: utf-8 -*-
"""The base exception class in agentscope."""
class AgentOrientedException(Exception):
"""The base class for all agent-oriented exceptions. These exceptions are
expect to the captured and exposed to the agent during runtime, so that
agents can handle the error appropriately during ... | 28 | 922 |
agentscope | src/agentscope/exception/__init__.py | .py | # -*- coding: utf-8 -*-
"""The exception module in agentscope."""
from ._base import (
AgentOrientedException,
DeveloperOrientedException,
)
from ._tool import (
ToolInterruptedError,
ToolNotFoundError,
ToolJSONDecodeError,
ToolGroupInactiveError,
)
__all__ = [
"AgentOrientedException",
... | 23 | 464 |
agentscope | src/agentscope/exception/_tool.py | .py | # -*- coding: utf-8 -*-
"""The tool-related exceptions in agentscope."""
from ._base import AgentOrientedException
class ToolNotFoundError(AgentOrientedException):
"""Exception raised when a tool was not found."""
class ToolInterruptedError(AgentOrientedException):
"""Exception raised when a tool calling w... | 21 | 595 |
agentscope | src/agentscope/tool/_constants.py | .py | # -*- coding: utf-8 -*-
"""Constants for tool permission system."""
DEFAULT_DANGEROUS_FILES = [
".gitconfig",
".gitmodules",
".bashrc",
".bash_profile",
".zshrc",
".zprofile",
".profile",
".ssh/config",
".ssh/authorized_keys",
".netrc",
".npmrc",
".pypirc",
".env",
... | 111 | 3,307 |
agentscope | src/agentscope/tool/_utils.py | .py | # -*- coding: utf-8 -*-
"""The tool module utils."""
import inspect
from typing import Any, Dict, Callable
from docstring_parser import parse
from pydantic import Field, create_model, ConfigDict
def _remove_title_field(schema: dict) -> dict:
"""Remove the title field from the JSON schema to avoid
misleading ... | 161 | 5,193 |
agentscope | src/agentscope/tool/_base.py | .py | # -*- coding: utf-8 -*-
# pylint: disable=unused-argument
"""The tool protocol in agentscope."""
import inspect
import os
from abc import abstractmethod, ABC
from pathlib import Path
from typing import AsyncGenerator, Any, Callable, List
from pydantic import BaseModel
from ._constants import DEFAULT_DANGEROUS_FILES, ... | 452 | 17,052 |
agentscope | src/agentscope/tool/_tool_group.py | .py | # -*- coding: utf-8 -*-
"""The tool group class."""
from typing import Literal, Sequence
from ..mcp import MCPClient
from ._base import ToolBase
from ..skill import SkillLoaderBase, Skill, LocalSkillLoader
class ToolGroup:
"""A group of related tools, mcps, and skills that an agent can activate,
deactivate a... | 109 | 3,929 |
agentscope | src/agentscope/tool/__init__.py | .py | # -*- coding: utf-8 -*-
"""The tool module in agentscope."""
from ._types import ToolChoice, Function, RegisteredTool
from ._response import ToolResponse, ToolChunk
from ._toolkit import Toolkit
from ._base import ToolBase, ParamsBase, ToolMiddlewareBase
from ._adapters import MCPTool, FunctionTool
from ._builtin impo... | 63 | 1,151 |
agentscope | src/agentscope/tool/_types.py | .py | # -*- coding: utf-8 -*-
"""The types for the tool module in AgentScope."""
from copy import deepcopy
from dataclasses import dataclass, field
from typing import (
Literal,
Type,
Any,
TypeAlias,
Coroutine,
AsyncGenerator,
Generator,
Awaitable,
Callable,
)
from pydantic import BaseMod... | 204 | 7,609 |
agentscope | src/agentscope/tool/_response.py | .py | # -*- coding: utf-8 -*-
"""The tool response class."""
import base64
import binascii
from typing import List, Literal, Self
from pydantic import BaseModel, Field
from .._utils._common import _generate_id
from ..message import DataBlock, TextBlock, Base64Source, ToolResultState
def _merge_base64_chunks(existing: str... | 171 | 6,682 |
agentscope | src/agentscope/tool/_adapters.py | .py | # -*- coding: utf-8 -*-
"""Adapters to convert functions and MCP tools to ToolProtocol."""
import inspect
import json
import re
from contextlib import _AsyncGeneratorContextManager
from datetime import timedelta
from typing import Callable, Any, AsyncGenerator, Generator
from mcp import ClientSession
import mcp
from ... | 395 | 13,880 |
agentscope | src/agentscope/tool/_toolkit.py | .py | # -*- coding: utf-8 -*-
"""The toolkit class for tool calls in AgentScope."""
import asyncio
import inspect
from collections import OrderedDict
from typing import (
AsyncGenerator,
Type,
Generator,
Sequence,
)
import mcp
from jinja2 import Template
from pydantic import (
BaseModel,
Field,
c... | 684 | 24,376 |
agentscope | src/agentscope/tool/_task/_task_tool_base.py | .py | # -*- coding: utf-8 -*-
"""The task tool base class, providing unified interface and permission
check for builtin task related tools."""
from typing import Any
from .._base import ToolBase
from ...permission import (
PermissionContext,
PermissionDecision,
PermissionBehavior,
)
class _TaskToolBase(ToolBas... | 43 | 945 |
agentscope | src/agentscope/tool/_task/_list_task.py | .py | # -*- coding: utf-8 -*-
"""The task list tool class."""
from ._task_tool_base import _TaskToolBase
from .._response import ToolChunk
from .._base import ParamsBase
from ...state import AgentState
from ...exception import DeveloperOrientedException
from ...message import TextBlock
class _TaskListParams(ParamsBase):
... | 75 | 2,703 |
agentscope | src/agentscope/tool/_task/__init__.py | .py | # -*- coding: utf-8 -*-
"""Task planning tools for agents."""
from ._create_task import TaskCreate
from ._get_task import TaskGet
from ._list_task import TaskList
from ._update_task import TaskUpdate
__all__ = [
"TaskCreate",
"TaskGet",
"TaskList",
"TaskUpdate",
]
| 14 | 282 |
agentscope | src/agentscope/tool/_task/_create_task.py | .py | # -*- coding: utf-8 -*-
"""The creating task tool class."""
from typing import Any
from pydantic import BaseModel, Field
from ._task_tool_base import _TaskToolBase
from .._response import ToolChunk
from ...state import AgentState, Task
from ...exception import DeveloperOrientedException
from ...message import TextBlo... | 133 | 4,637 |
agentscope | src/agentscope/tool/_task/_get_task.py | .py | # -*- coding: utf-8 -*-
"""The get task tool class."""
from pydantic import BaseModel, Field
from ._task_tool_base import _TaskToolBase
from .._response import ToolChunk
from ...state import AgentState
from ...exception import DeveloperOrientedException
from ...message import TextBlock, ToolResultState
class _TaskGe... | 101 | 3,011 |
agentscope | src/agentscope/tool/_task/_update_task.py | .py | # -*- coding: utf-8 -*-
"""The task updated tool class."""
from typing import Literal
from pydantic import BaseModel, Field
from ._task_tool_base import _TaskToolBase
from .._response import ToolChunk
from ...state import AgentState
from ...exception import DeveloperOrientedException
from ...message import TextBlock,... | 294 | 9,572 |
agentscope | src/agentscope/tool/_builtin/_meta.py | .py | # -*- coding: utf-8 -*-
"""The meta tool class."""
from typing import Any, List
from pydantic import Field, create_model
from jinja2 import Template
from .._tool_group import ToolGroup
from ...permission import (
PermissionContext,
PermissionDecision,
PermissionBehavior,
)
from .._response import ToolChun... | 155 | 5,534 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.