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/tool/_builtin/__init__.py | .py | # -*- coding: utf-8 -*-
"""The builtin tools in agentscope."""
from ._backend import BackendBase, DirEntry, ExecResult, LocalBackend
from ._bash import Bash
from ._edit import Edit
from ._glob import Glob
from ._grep import Grep
from ._meta import ResetTools
from ._powershell import PowerShell
from ._read import Read
... | 30 | 594 |
agentscope | src/agentscope/tool/_builtin/_grep.py | .py | # -*- coding: utf-8 -*-
"""The grep tool in agentscope."""
import fnmatch
from typing import Any, List, Literal
from .._base import ToolBase, ToolMiddlewareBase
from ...permission import (
PermissionContext,
PermissionDecision,
PermissionBehavior,
PermissionRule,
)
from .._response import ToolChunk
fro... | 489 | 16,875 |
agentscope | src/agentscope/tool/_builtin/_read.py | .py | # -*- coding: utf-8 -*-
"""The read tool in agentscope."""
import fnmatch
from typing import Any, List
from .._base import ToolBase, ToolMiddlewareBase
from ...permission import (
PermissionContext,
PermissionDecision,
PermissionBehavior,
PermissionRule,
)
from .._response import ToolChunk
from ...mess... | 286 | 10,596 |
agentscope | src/agentscope/tool/_builtin/_powershell.py | .py | # -*- coding: utf-8 -*-
"""The PowerShell tool in agentscope."""
import base64
import os
from typing import AsyncGenerator, Any, List
from ._backend import BackendBase, LocalBackend, _normalize_newlines
from .._base import ToolBase, ToolMiddlewareBase
from .._response import ToolChunk
from ...message import TextBlock... | 282 | 10,081 |
agentscope | src/agentscope/tool/_builtin/_skill.py | .py | # -*- coding: utf-8 -*-
"""The builtin skill viewer tool."""
from typing import Any, Callable, Awaitable, List
from ...exception import DeveloperOrientedException
from ...permission import (
PermissionContext,
PermissionDecision,
PermissionBehavior,
)
from .._response import ToolChunk
from .._base import T... | 128 | 4,029 |
agentscope | src/agentscope/tool/_builtin/_backend.py | .py | # -*- coding: utf-8 -*-
"""Backend abstraction for builtin tools.
Provides a :class:`BackendBase` abstract base class that captures the
core I/O primitives shared across all six builtin tools (Bash, Read,
Write, Edit, Grep, Glob).
Every backend implements exactly **three** abstract primitives whose
mechanism genuinel... | 1,065 | 37,535 |
agentscope | src/agentscope/tool/_builtin/_bash_parser.py | .py | # -*- coding: utf-8 -*-
"""Bash command parser using tree-sitter for precise syntax analysis.
This module provides utilities to parse Bash commands and extract meaningful
information for permission rule generation, including:
- Splitting compound commands (&&, ||, ;, |)
- Extracting command prefixes (e.g., "npm run" f... | 924 | 28,652 |
agentscope | src/agentscope/tool/_builtin/_write.py | .py | # -*- coding: utf-8 -*-
"""The write tool in agentscope."""
import difflib
import fnmatch
from pathlib import Path
from typing import Any, List
from .._base import ToolBase, ToolMiddlewareBase
from .._constants import (
DEFAULT_DANGEROUS_FILES,
DEFAULT_DANGEROUS_DIRECTORIES,
)
from ...permission import (
P... | 335 | 12,630 |
agentscope | src/agentscope/tool/_builtin/_bash.py | .py | # -*- coding: utf-8 -*-
"""The bash tool in agentscope."""
import os
from typing import AsyncGenerator, Any, List
import re
from ._bash_parser import BashCommandParser
from .._base import ToolBase, ToolMiddlewareBase
from .._constants import (
DEFAULT_DANGEROUS_FILES,
DEFAULT_DANGEROUS_DIRECTORIES,
)
from ...p... | 790 | 31,414 |
agentscope | src/agentscope/tool/_builtin/_glob.py | .py | # -*- coding: utf-8 -*-
"""The glob tool in agentscope."""
from __future__ import annotations
import fnmatch
import json
import sys
from typing import TYPE_CHECKING, Any, List
from ...message import TextBlock, ToolResultState
from ...permission import (
PermissionBehavior,
PermissionContext,
PermissionDe... | 306 | 10,746 |
agentscope | src/agentscope/tool/_builtin/_edit.py | .py | # -*- coding: utf-8 -*-
"""The edit tool in agentscope."""
import difflib
import fnmatch
from typing import Any, List
from .._base import ToolBase, ToolMiddlewareBase
from .._constants import (
DEFAULT_DANGEROUS_FILES,
DEFAULT_DANGEROUS_DIRECTORIES,
)
from ...permission import (
PermissionContext,
Perm... | 423 | 15,390 |
agentscope | src/agentscope/tool/_builtin/_scripts/__init__.py | .py | # -*- coding: utf-8 -*-
"""Standalone helper scripts shipped as package resources.
Scripts in this package are deployed into remote workspaces (Docker /
E2B) at initialization time and invoked via ``exec_shell``. They must
remain importable *without* ``agentscope`` installed — the host reads
them as raw bytes via :mod... | 10 | 396 |
agentscope | src/agentscope/tool/_builtin/_scripts/_glob_helper.py | .py | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Standalone glob helper script for agentscope builtin tools.
This script is designed to run **without** agentscope installed. It is
deployed into remote workspaces (Docker / E2B) at initialization time
and invoked via ``exec_shell`` by the :class:`Glob` tool.
Usage::
... | 216 | 7,121 |
agentscope | src/agentscope/model/_utils.py | .py | # -*- coding: utf-8 -*-
"""Internal utilities for the model module."""
import base64
from typing import Any, Self, TypeAlias
from pydantic import Field
from ._model_response import ChatResponse, FinishedReason
from ._model_usage import ChatUsage
from .._logging import logger
from ..message import (
Base64Source,
... | 281 | 9,601 |
agentscope | src/agentscope/model/_base.py | .py | # -*- coding: utf-8 -*-
"""The base class for the chat models."""
import asyncio
import inspect
import json
from abc import abstractmethod
from copy import deepcopy
from pathlib import Path
from typing import Type, Any, AsyncGenerator
import jsonschema
from pydantic import BaseModel
from ._model_response import Struc... | 647 | 23,862 |
agentscope | src/agentscope/model/__init__.py | .py | # -*- coding: utf-8 -*-
"""The model module."""
from ._base import ChatModelBase
from ._model_card import ModelCard
from ._model_response import ChatResponse, StructuredResponse, FinishedReason
from ._model_usage import ChatUsage
from ._anthropic import AnthropicChatModel
from ._dashscope import DashScopeChatModel
fro... | 35 | 952 |
agentscope | src/agentscope/model/_model_response.py | .py | # -*- coding: utf-8 -*-
"""The model response module."""
import base64
from dataclasses import dataclass, field
from datetime import datetime
from enum import StrEnum
from typing import Any, Literal, Self, List
from ._model_usage import ChatUsage
from .._utils._common import _generate_id
from .._utils._mixin import Di... | 351 | 13,411 |
agentscope | src/agentscope/model/_model_card.py | .py | # -*- coding: utf-8 -*-
"""The model card class."""
import copy
from datetime import datetime
from typing import Literal, Self, Type
import yaml
from pydantic import BaseModel, Field
class ModelCard(BaseModel):
"""The model card class."""
type: Literal["chat_model"] = "chat_model"
"""The model card type... | 162 | 5,422 |
agentscope | src/agentscope/model/_model_usage.py | .py | # -*- coding: utf-8 -*-
"""The model usage class in agentscope."""
from dataclasses import dataclass, field
from typing import Any, Literal
from .._utils._mixin import DictMixin
@dataclass
class ChatUsage(DictMixin):
"""The usage of a chat model API invocation."""
input_tokens: int
"""The number of inpu... | 33 | 967 |
agentscope | src/agentscope/model/_gemini/__init__.py | .py | # -*- coding: utf-8 -*-
"""The Google Gemini LLM API modules."""
from ._model import GeminiCredential, GeminiChatModel
__all__ = [
"GeminiCredential",
"GeminiChatModel",
]
| 10 | 182 |
agentscope | src/agentscope/model/_gemini/_model.py | .py | # -*- coding: utf-8 -*-
"""The Google Gemini chat model implementation."""
import base64
import json
from datetime import datetime
from typing import Literal, Any, AsyncGenerator, TYPE_CHECKING, List, Type
from pydantic import BaseModel, Field
from ..._utils._common import _generate_id, _flatten_json_schema
from .._b... | 555 | 20,368 |
agentscope | src/agentscope/model/_xai/__init__.py | .py | # -*- coding: utf-8 -*-
"""The xAI LLM API modules."""
from ._model import XAICredential, XAIChatModel
__all__ = [
"XAICredential",
"XAIChatModel",
]
| 10 | 160 |
agentscope | src/agentscope/model/_xai/_model.py | .py | # -*- coding: utf-8 -*-
"""The xAI chat model implementation using the official xai_sdk."""
from datetime import datetime
from typing import Any, AsyncGenerator, List, Literal, TYPE_CHECKING, Type
from pydantic import BaseModel, Field
from ..._utils._common import _generate_id
from .._base import ChatModelBase, _TOOL... | 455 | 16,430 |
agentscope | src/agentscope/model/_openai_response/__init__.py | .py | # -*- coding: utf-8 -*-
"""The OpenAI Responses API modules."""
from ._model import OpenAIResponseModel
__all__ = [
"OpenAIResponseModel",
]
| 9 | 147 |
agentscope | src/agentscope/model/_openai_response/_model.py | .py | # -*- coding: utf-8 -*-
"""The OpenAI Responses API chat model implementation."""
from collections import OrderedDict
from datetime import datetime
from typing import Literal, Any, AsyncGenerator, List, TYPE_CHECKING, Type
from pydantic import BaseModel, Field
from ..._utils._common import _generate_id
from .._base i... | 486 | 18,716 |
agentscope | src/agentscope/model/_moonshot/__init__.py | .py | # -*- coding: utf-8 -*-
"""The Moonshot AI LLM API modules."""
from ._model import MoonshotChatModel
__all__ = [
"MoonshotChatModel",
]
| 9 | 142 |
agentscope | src/agentscope/model/_moonshot/_model.py | .py | # -*- coding: utf-8 -*-
"""The Moonshot AI chat model implementation."""
from collections import OrderedDict
from datetime import datetime
from typing import Literal, Any, AsyncGenerator, TYPE_CHECKING, List, Type
from pydantic import BaseModel, Field
from .._base import ChatModelBase, _TOOL_CHOICE_LITERAL_MODES
from... | 481 | 17,716 |
agentscope | src/agentscope/model/_dashscope/__init__.py | .py | # -*- coding: utf-8 -*-
"""The DashScope API modules."""
from ._model import DashScopeChatModel, DashScopeCredential
__all__ = [
"DashScopeChatModel",
"DashScopeCredential",
]
| 10 | 186 |
agentscope | src/agentscope/model/_dashscope/_model.py | .py | # -*- coding: utf-8 -*-
"""The DashScope chat model class (OpenAI-compatible implementation)."""
import base64
import warnings
from collections import OrderedDict
from datetime import datetime
from typing import Any, AsyncGenerator, List, Literal, Type, TYPE_CHECKING
from pydantic import BaseModel, Field
from ..._uti... | 580 | 21,941 |
agentscope | src/agentscope/model/_anthropic/__init__.py | .py | # -*- coding: utf-8 -*-
"""The Anthropic LLM API modules."""
from ._model import AnthropicCredential, AnthropicChatModel
__all__ = [
"AnthropicCredential",
"AnthropicChatModel",
]
| 10 | 190 |
agentscope | src/agentscope/model/_anthropic/_model.py | .py | # -*- coding: utf-8 -*-
"""The Anthropic chat model implementation."""
import json
from collections import OrderedDict
from datetime import datetime
from typing import Literal, Any, AsyncGenerator, TYPE_CHECKING, List, Type
from pydantic import BaseModel, Field
from .._base import ChatModelBase, _TOOL_CHOICE_LITERAL_... | 632 | 24,031 |
agentscope | src/agentscope/model/_ollama/__init__.py | .py | # -*- coding: utf-8 -*-
"""The Ollama LLM API modules."""
from ._model import OllamaCredential, OllamaChatModel
__all__ = [
"OllamaCredential",
"OllamaChatModel",
]
| 10 | 175 |
agentscope | src/agentscope/model/_ollama/_model.py | .py | # -*- coding: utf-8 -*-
"""The Ollama chat model implementation."""
import json
from datetime import datetime
from typing import Literal, Any, AsyncGenerator, TYPE_CHECKING, List, Type
from pydantic import BaseModel, Field
from ..._utils._common import _generate_id
from .._base import ChatModelBase
from .._model_resp... | 349 | 12,281 |
agentscope | src/agentscope/model/_deepseek/__init__.py | .py | # -*- coding: utf-8 -*-
"""The DeepSeek LLM API modules."""
from ._model import DeepSeekCredential, DeepSeekChatModel
__all__ = [
"DeepSeekCredential",
"DeepSeekChatModel",
]
| 10 | 185 |
agentscope | src/agentscope/model/_deepseek/_model.py | .py | # -*- coding: utf-8 -*-
"""The DeepSeek chat model implementation."""
from collections import OrderedDict
from datetime import datetime
from typing import Literal, Any, AsyncGenerator, TYPE_CHECKING, List, Type
from pydantic import BaseModel, Field
from .._base import ChatModelBase, _TOOL_CHOICE_LITERAL_MODES
from ..... | 477 | 17,636 |
agentscope | src/agentscope/model/_openai_chat/__init__.py | .py | # -*- coding: utf-8 -*-
"""The OpenAI Chat Completions API modules."""
from ._model import OpenAIChatModel
__all__ = [
"OpenAIChatModel",
]
| 9 | 146 |
agentscope | src/agentscope/model/_openai_chat/_model.py | .py | # -*- coding: utf-8 -*-
"""The OpenAI Chat Completions model implementation."""
import warnings
import base64
from collections import OrderedDict
from datetime import datetime
from typing import Literal, Any, AsyncGenerator, TYPE_CHECKING, List, Type
from pydantic import BaseModel, Field
from ..._utils._audio import ... | 669 | 25,367 |
agentscope | src/agentscope/console/_renderer.py | .py | # -*- coding: utf-8 -*-
"""Render agent event streams as human-readable terminal output."""
import json
from typing import Literal
from rich.console import Console
from rich.panel import Panel
from rich.text import Text
from ..event import (
AgentEvent,
DataBlockEndEvent,
HintBlockEvent,
ModelCallEndE... | 428 | 15,446 |
agentscope | src/agentscope/console/_console.py | .py | # -*- coding: utf-8 -*-
"""The interactive console entry for trying an agent in the terminal."""
import asyncio
import signal
from ._renderer import ConsoleRenderer, Verbosity
from ..agent import Agent
from ..event import (
ConfirmResult,
RequireUserConfirmEvent,
UserConfirmResultEvent,
UserInterruptEv... | 166 | 5,597 |
agentscope | src/agentscope/console/__init__.py | .py | # -*- coding: utf-8 -*-
"""The console module for viewing and trying agents in the terminal.
Two public entries serve two different scenarios:
- :class:`ConsoleRenderer`: a passive event renderer that turns an
:class:`~agentscope.event.AgentEvent` stream into line-based terminal
output. Embed it in your own code ... | 21 | 766 |
agentscope | src/agentscope/permission/_decision.py | .py | # -*- coding: utf-8 -*-
"""The permission decision result."""
from dataclasses import dataclass
from typing import Any
from ._rule import PermissionRule
from ._types import PermissionBehavior
@dataclass
class PermissionDecision:
"""Decision result from permission checking.
Represents the outcome of a permis... | 69 | 2,762 |
agentscope | src/agentscope/permission/__init__.py | .py | # -*- coding: utf-8 -*-
"""The tool permission related types and functions."""
from ._context import PermissionContext, AdditionalWorkingDirectory
from ._decision import PermissionDecision
from ._engine import PermissionEngine
from ._rule import PermissionRule
from ._types import PermissionMode, PermissionBehavior
__... | 19 | 511 |
agentscope | src/agentscope/permission/_engine.py | .py | # -*- coding: utf-8 -*-
"""The permission engine for checking and enforcing permission rules."""
from typing import Any, List, TYPE_CHECKING
from ._context import PermissionContext
from ._rule import PermissionRule
from ._decision import PermissionDecision, PermissionBehavior
from ._types import PermissionMode
from ..... | 849 | 33,924 |
agentscope | src/agentscope/permission/_rule.py | .py | # -*- coding: utf-8 -*-
"""Permission rule model for tool usage."""
from pydantic import BaseModel
from ._types import PermissionBehavior
class PermissionRule(BaseModel):
"""Permission rule for tool usage.
A permission rule defines whether a specific tool or tool operation
should be allowed, denied, or ... | 37 | 1,213 |
agentscope | src/agentscope/permission/_types.py | .py | # -*- coding: utf-8 -*-
# pylint: disable=line-too-long
"""Permission system types and engine for tool usage control.
This module implements a permission system that controls tool execution based
on configurable rules. The permission system supports different matching
strategies depending on the tool type:
- For Bash... | 103 | 6,452 |
agentscope | src/agentscope/permission/_context.py | .py | # -*- coding: utf-8 -*-
"""The permission context module."""
from pydantic import BaseModel, Field
from ._rule import PermissionRule
from ._types import PermissionMode
class AdditionalWorkingDirectory(BaseModel):
"""An additional directory included in permission scope.
Working directories are used to determ... | 47 | 1,513 |
agentscope | src/agentscope/formatter/_formatter_base.py | .py | # -*- coding: utf-8 -*-
"""The formatter module."""
import base64
import mimetypes
import tempfile
from abc import abstractmethod
from fnmatch import fnmatch
from typing import Any, List, AsyncGenerator
import shortuuid
from pydantic import BaseModel, Field
from ..message import (
Msg,
DataBlock,
TextBloc... | 218 | 8,031 |
agentscope | src/agentscope/formatter/_gemini_formatter.py | .py | # -*- coding: utf-8 -*-
"""Google Gemini API formatter in agentscope."""
import base64
import fnmatch
from abc import ABC
from typing import Any
import requests
from pydantic import Field
from ._formatter_base import FormatterBase
from .._logging import logger
from .._utils._common import _json_loads_with_repair
from... | 446 | 15,646 |
agentscope | src/agentscope/formatter/_moonshot_formatter.py | .py | # -*- coding: utf-8 -*-
"""The Moonshot AI formatter for agentscope."""
import base64
from typing import Any
import requests
from pydantic import Field
from ._openai_formatter import _OpenAIFormatterBase
from .._logging import logger
from ..message import (
Msg,
URLSource,
Base64Source,
TextBlock,
... | 418 | 15,495 |
agentscope | src/agentscope/formatter/_openai_response_formatter.py | .py | # -*- coding: utf-8 -*-
"""Formatters for the OpenAI Responses API."""
from abc import ABC
from typing import Any
from pydantic import Field
from ._openai_formatter import _OpenAIFormatterBase
from .._logging import logger
from ..message import (
Msg,
TextBlock,
DataBlock,
ToolCallBlock,
ToolResul... | 484 | 17,690 |
agentscope | src/agentscope/formatter/_dashscope_formatter.py | .py | # -*- coding: utf-8 -*-
"""The DashScope formatter module (OpenAI-compatible format)."""
import base64
from typing import Any
from fnmatch import fnmatch
from abc import ABC
from pydantic import Field
from ._formatter_base import FormatterBase
from .._logging import logger
from ..message import (
Msg,
TextBl... | 566 | 20,557 |
agentscope | src/agentscope/formatter/_openai_formatter.py | .py | # -*- coding: utf-8 -*-
"""The OpenAI formatter for agentscope."""
import base64
from abc import ABC
from fnmatch import fnmatch
from typing import Any
from urllib.parse import urlparse
import requests
from pydantic import Field
from ._formatter_base import FormatterBase
from .._logging import logger
from ..message i... | 514 | 18,346 |
agentscope | src/agentscope/formatter/__init__.py | .py | # -*- coding: utf-8 -*-
"""The formatter module in agentscope."""
from ._formatter_base import FormatterBase
from ._dashscope_formatter import (
DashScopeChatFormatter,
DashScopeMultiAgentFormatter,
)
from ._anthropic_formatter import (
AnthropicChatFormatter,
AnthropicMultiAgentFormatter,
)
from ._ope... | 63 | 1,573 |
agentscope | src/agentscope/formatter/_ollama_formatter.py | .py | # -*- coding: utf-8 -*-
"""The Ollama formatter module."""
import base64
import fnmatch
from abc import ABC
from typing import Any
import requests
from pydantic import Field
from ._formatter_base import FormatterBase
from .._logging import logger
from .._utils._common import _json_loads_with_repair
from ..message imp... | 453 | 16,421 |
agentscope | src/agentscope/formatter/_xai_formatter.py | .py | # -*- coding: utf-8 -*-
"""The xAI formatter module.
This formatter converts AgentScope ``Msg`` objects into the protobuf
``Message`` objects expected by the ``xai_sdk`` gRPC client. Unlike every
other formatter, the ``format()`` method returns a list of
``chat_pb2.Message`` proto objects rather than plain dicts, bec... | 486 | 19,446 |
agentscope | src/agentscope/formatter/_deepseek_formatter.py | .py | # -*- coding: utf-8 -*-
"""The DeepSeek formatter module."""
from typing import Any
from pydantic import Field
from ._formatter_base import FormatterBase
from .._logging import logger
from ..message import (
Msg,
TextBlock,
DataBlock,
ThinkingBlock,
HintBlock,
ToolCallBlock,
ToolResultBloc... | 314 | 11,248 |
agentscope | src/agentscope/formatter/_anthropic_formatter.py | .py | # -*- coding: utf-8 -*-
"""The Anthropic formatter module."""
import base64
import fnmatch
from abc import ABC
from typing import Any
import requests
from pydantic import Field
from ._formatter_base import FormatterBase
from .._logging import logger
from .._utils._common import _json_loads_with_repair
from ..message ... | 553 | 21,178 |
agentscope | src/agentscope/mcp/_config.py | .py | # -*- coding: utf-8 -*-
"""The MCP configurations."""
from pathlib import Path
from typing import Literal
from pydantic import BaseModel, Field
class StdioMCPConfig(BaseModel):
"""The STDIO MCP server configuration."""
type: Literal["stdio_mcp"] = "stdio_mcp"
command: str = Field(
title="Comman... | 65 | 1,656 |
agentscope | src/agentscope/mcp/__init__.py | .py | # -*- coding: utf-8 -*-
"""The MCP module in AgentScope, that provides fine-grained control over
the MCP servers."""
from ._config import StdioMCPConfig, HttpMCPConfig
from ._mcp_client import MCPClient
__all__ = [
"MCPClient",
"StdioMCPConfig",
"HttpMCPConfig",
]
| 14 | 280 |
agentscope | src/agentscope/mcp/_mcp_client.py | .py | # -*- coding: utf-8 -*-
"""Unified MCP client implementation for AgentScope."""
import re
from contextlib import AsyncExitStack, _AsyncGeneratorContextManager
from typing import Any, TYPE_CHECKING
import httpx
import mcp.types
from mcp import ClientSession, stdio_client, StdioServerParameters
from mcp.client.sse impor... | 438 | 14,962 |
agentscope | src/agentscope/middleware/_tts_middleware.py | .py | # -*- coding: utf-8 -*-
"""Middleware that turns reasoning text into speech and injects it as
``DATA_BLOCK_*`` events into the agent's event stream."""
from typing import TYPE_CHECKING, AsyncGenerator, Callable
from ._base import MiddlewareBase
from .._utils._common import _generate_id
from ..event import (
DataBl... | 180 | 6,889 |
agentscope | src/agentscope/middleware/_base.py | .py | # -*- coding: utf-8 -*-
"""Base middleware class for AgentScope middleware system."""
from typing import AsyncGenerator, Awaitable, Callable, TYPE_CHECKING
from ..tool import ToolBase
if TYPE_CHECKING:
from ..agent import Agent
from ..model import ChatResponse
from ..permission import PermissionDecision
... | 304 | 11,166 |
agentscope | src/agentscope/middleware/__init__.py | .py | # -*- coding: utf-8 -*-
"""Middleware system for AgentScope agents."""
from ._base import MiddlewareBase
from ._rag import RAGMiddleware
from ._budget import ReplyBudgetControlMiddleware
from ._longterm_memory import (
AgenticMemoryMiddleware,
Mem0Middleware,
ReMeMiddleware,
)
from ._tracing import Tracing... | 25 | 589 |
agentscope | src/agentscope/middleware/_rag.py | .py | # -*- coding: utf-8 -*-
"""RAG middleware that brings knowledge-base search into the agent loop.
The :class:`RAGMiddleware` wraps one or more
:class:`~agentscope.rag.KnowledgeBase` runtime handles — each carrying
its own embedding model, vector store, and (optional) metadata filter —
so a single agent can search acros... | 766 | 28,738 |
agentscope | src/agentscope/middleware/_budget.py | .py | # -*- coding: utf-8 -*-
"""Budget control middleware for AgentScope agents."""
from typing import AsyncGenerator, Callable, TYPE_CHECKING
from ..event import ModelCallEndEvent, ReplyStartEvent, ReplyEndEvent
from ..message import AssistantMsg, HintBlock
from ..tool import ToolChoice
from ._base import MiddlewareBase
... | 208 | 8,037 |
agentscope | src/agentscope/middleware/_tracing/_utils.py | .py | # -*- coding: utf-8 -*-
"""Serialize objects to JSON string."""
import datetime
import enum
import inspect
import json
from dataclasses import is_dataclass
from typing import Any
from pydantic import BaseModel
from ...message import Msg
def _to_serializable(
obj: Any,
) -> Any:
"""Convert an object to a JSO... | 79 | 1,784 |
agentscope | src/agentscope/middleware/_tracing/_attributes.py | .py | # -*- coding: utf-8 -*-
"""The tracing types class in agentscope."""
from opentelemetry.semconv._incubating.attributes import (
gen_ai_attributes as GenAIAttributes,
)
class SpanAttributes:
"""The span attributes."""
# GenAI Common Attributes
GEN_AI_CONVERSATION_ID = GenAIAttributes.GEN_AI_CONVERSATI... | 202 | 6,665 |
agentscope | src/agentscope/middleware/_tracing/_trace.py | .py | # -*- coding: utf-8 -*-
"""TracingMiddleware and supporting utilities for OpenTelemetry tracing."""
import json
from typing import (
Any,
AsyncGenerator,
Callable,
Awaitable,
Union,
TypeVar,
TYPE_CHECKING,
)
import aioitertools
from opentelemetry import context as otel_context
from opentel... | 375 | 12,705 |
agentscope | src/agentscope/middleware/_tracing/_setup.py | .py | # -*- coding: utf-8 -*-
"""The tracing interface class in agentscope."""
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from opentelemetry.trace import Tracer
else:
Tracer = "Tracer"
def _get_tracer() -> Tracer:
"""Get the tracer
Returns:
`Tracer`: The tracer with the name "agentscope" an... | 20 | 471 |
agentscope | src/agentscope/middleware/_tracing/_extractor.py | .py | # -*- coding: utf-8 -*-
"""Extract attributes from AgentScope components for OpenTelemetry tracing."""
import inspect
from typing import Any, Dict, TYPE_CHECKING
from ...message import Msg, ToolCallBlock
from ._attributes import (
SpanAttributes,
OperationNameValues,
ProviderNameValues,
)
from ._converter... | 609 | 20,072 |
agentscope | src/agentscope/middleware/_tracing/__init__.py | .py | # -*- coding: utf-8 -*-
"""The tracing interface class in agentscope."""
from ._trace import TracingMiddleware
__all__ = [
"TracingMiddleware",
]
| 9 | 152 |
agentscope | src/agentscope/middleware/_tracing/_converter.py | .py | # -*- coding: utf-8 -*-
"""Convert ContentBlock to OpenTelemetry GenAI part format."""
import json
from typing import Any, Dict
from ...message import (
ContentBlock,
TextBlock,
ThinkingBlock,
ToolCallBlock,
ToolResultBlock,
DataBlock,
Base64Source,
URLSource,
)
from ._utils import _s... | 122 | 3,504 |
agentscope | src/agentscope/middleware/_longterm_memory/__init__.py | .py | # -*- coding: utf-8 -*-
"""Long-term memory middlewares for AgentScope agents."""
from ._agentic_memory import AgenticMemoryMiddleware
from ._mem0 import Mem0Middleware
from ._reme import ReMeMiddleware
__all__ = [
"AgenticMemoryMiddleware",
"Mem0Middleware",
"ReMeMiddleware",
]
| 13 | 294 |
agentscope | src/agentscope/middleware/_longterm_memory/_agentic_memory/__init__.py | .py | # -*- coding: utf-8 -*-
"""File-backed long-term memory middleware."""
from ._middleware import AgenticMemoryMiddleware
__all__ = ["AgenticMemoryMiddleware"]
| 7 | 160 |
agentscope | src/agentscope/middleware/_longterm_memory/_agentic_memory/_middleware.py | .py | # -*- coding: utf-8 -*-
"""Filesystem-backed long-term memory middleware.
The middleware keeps a workspace-local Markdown memory store, injects a
bounded ``MEMORY.md`` index into the system prompt, and can asynchronously
surface relevant topic files as hint blocks during the reasoning loop.
"""
from __future__ import ... | 954 | 37,965 |
agentscope | src/agentscope/middleware/_longterm_memory/_mem0/_utils.py | .py | # -*- coding: utf-8 -*-
"""Pure helper functions for the mem0 middleware.
These are stateless adapters that translate between AgentScope and
mem0 data shapes. Keeping them out of the middleware class makes them
trivial to unit-test in isolation.
"""
from __future__ import annotations
from typing import Any
from ....... | 77 | 2,474 |
agentscope | src/agentscope/middleware/_longterm_memory/_mem0/__init__.py | .py | # -*- coding: utf-8 -*-
"""mem0-backed long-term memory middleware."""
from ._middleware import Mem0Middleware
__all__ = ["Mem0Middleware"]
| 7 | 142 |
agentscope | src/agentscope/middleware/_longterm_memory/_mem0/_agentscope_adapter.py | .py | # -*- coding: utf-8 -*-
"""Adapters that let mem0 drive its memory extraction with the user's
existing AgentScope chat / embedding model — instead of building yet
another OpenAI / Anthropic / Ollama client just for mem0.
Two pieces:
- :class:`AgentScopeLLM` — implements ``mem0.llms.base.LLMBase`` by
delegating to a... | 440 | 16,680 |
agentscope | src/agentscope/middleware/_longterm_memory/_mem0/_middleware.py | .py | # -*- coding: utf-8 -*-
"""mem0-backed long-term memory middleware for AgentScope agents.
Works with either ``mem0.AsyncMemory`` (open-source) or
``mem0.AsyncMemoryClient`` (hosted Platform). Both clients converge on
the same call shape:
- ``search(query, filters={"user_id": ..., "agent_id": ...}, top_k=...)``
- ``ad... | 742 | 29,178 |
agentscope | src/agentscope/middleware/_longterm_memory/_mem0/_tools.py | .py | # -*- coding: utf-8 -*-
# pylint: disable=protected-access
"""Agent-control tools exposed by the mem0 middleware.
These ``search_memory`` / ``add_memory`` tools are listed by
:class:`Mem0Middleware` when ``mode`` is ``"agent_control"`` or
``"both"``. Callers pass them into the agent's toolkit explicitly.
Each tool rea... | 271 | 9,354 |
agentscope | src/agentscope/middleware/_longterm_memory/_reme/_utils.py | .py | # -*- coding: utf-8 -*-
"""Pure helper functions for the ReMe middleware.
These are stateless adapters that translate between AgentScope and ReMe
data shapes. Keeping them out of the middleware class makes them trivial
to unit-test in isolation.
"""
from __future__ import annotations
from typing import Any
from ....... | 105 | 3,297 |
agentscope | src/agentscope/middleware/_longterm_memory/_reme/__init__.py | .py | # -*- coding: utf-8 -*-
"""ReMe-backed long-term memory middleware for AgentScope.
`ReMe <https://github.com/agentscope-ai/ReMe>`_ (``reme-ai``) is a
file-based memory toolkit built on AgentScope. This package embeds the
ReMe application in-process and exposes:
- :class:`ReMeMiddleware` — AgentScope middleware wiring... | 17 | 546 |
agentscope | src/agentscope/middleware/_longterm_memory/_reme/_middleware.py | .py | # -*- coding: utf-8 -*-
"""ReMe-backed long-term memory middleware for AgentScope agents.
`ReMe <https://github.com/agentscope-ai/ReMe>`_ is a file-based memory
toolkit built on AgentScope. This middleware **embeds the ReMe
application in-process** (no separate service to run); a chat model for
ReMe's LLM-backed jobs ... | 565 | 24,018 |
agentscope | src/agentscope/middleware/_longterm_memory/_reme/_tools.py | .py | # -*- coding: utf-8 -*-
# pylint: disable=protected-access
"""Agent-control tool exposed by the ReMe middleware.
The single ``memory_search`` tool is listed by :class:`ReMeMiddleware`
when ``mode`` is ``"agent_control"`` or ``"both"``. The tool drives
ReMe's ``search`` action through the embedded ReMe app held on the
... | 183 | 5,996 |
agentscope | src/agentscope/tts/_tts_response.py | .py | # -*- coding: utf-8 -*-
"""The TTS response module."""
from dataclasses import dataclass, field
from typing import Literal
from .._utils._common import _get_timestamp
from .._utils._mixin import DictMixin
from ..message import DataBlock
from ..types import JSONSerializableObject
@dataclass
class TTSUsage(DictMixin):... | 57 | 1,710 |
agentscope | src/agentscope/tts/__init__.py | .py | # -*- coding: utf-8 -*-
"""The TTS (Text-to-Speech) module in AgentScope."""
from ._tts_base import TTSModelBase
from ._tts_model_card import TTSModelCard
from ._tts_response import TTSResponse, TTSUsage
from ._dashscope import (
DashScopeCosyVoiceTTSModel,
DashScopeTTSModel,
DashScopeRealtimeTTSModel,
)
f... | 26 | 617 |
agentscope | src/agentscope/tts/_tts_base.py | .py | # -*- coding: utf-8 -*-
"""The TTS model base class."""
import inspect
from abc import abstractmethod
from pathlib import Path
from typing import TYPE_CHECKING, Any, AsyncGenerator
from pydantic import BaseModel
from ._tts_response import TTSResponse
from .._logging import logger
from ..credential import CredentialBa... | 213 | 7,346 |
agentscope | src/agentscope/tts/_tts_model_card.py | .py | # -*- coding: utf-8 -*-
"""The TTS model card class."""
import copy
from datetime import datetime
from typing import Literal, Self, Type
import yaml
from pydantic import BaseModel, Field
class TTSModelCard(BaseModel):
"""The model card class for TTS models."""
type: Literal["tts_model"] = "tts_model"
""... | 135 | 4,148 |
agentscope | src/agentscope/tts/_gemini/__init__.py | .py | # -*- coding: utf-8 -*-
"""The Gemini TTS module."""
from ._model import GeminiTTSModel
__all__ = [
"GeminiTTSModel",
]
| 9 | 126 |
agentscope | src/agentscope/tts/_gemini/_model.py | .py | # -*- coding: utf-8 -*-
"""Gemini TTS model implementation using the ``generateContent`` API."""
import base64
import io
import wave
from datetime import datetime
from typing import (
Any,
AsyncGenerator,
AsyncIterator,
Literal,
TYPE_CHECKING,
)
from pydantic import BaseModel, Field
from .._tts_ba... | 330 | 11,886 |
agentscope | src/agentscope/tts/_openai/__init__.py | .py | # -*- coding: utf-8 -*-
"""The OpenAI TTS module."""
from ._model import OpenAITTSModel
__all__ = [
"OpenAITTSModel",
]
| 9 | 126 |
agentscope | src/agentscope/tts/_openai/_model.py | .py | # -*- coding: utf-8 -*-
"""OpenAI TTS model implementation using the Audio Speech API."""
import base64
from datetime import datetime
from typing import (
Any,
AsyncGenerator,
Literal,
TYPE_CHECKING,
)
from pydantic import BaseModel, Field
from .._tts_base import TTSModelBase
from .._tts_response impo... | 257 | 8,278 |
agentscope | src/agentscope/tts/_dashscope/_cosyvoice_model.py | .py | # -*- coding: utf-8 -*-
"""DashScope CosyVoice TTS model implementation."""
import asyncio
import base64
import io
import os
from typing import Any, AsyncGenerator, Literal, TYPE_CHECKING
import wave
from pydantic import BaseModel, Field
from .._tts_base import TTSModelBase
from .._tts_model_card import TTSModelCard
... | 398 | 13,726 |
agentscope | src/agentscope/tts/_dashscope/__init__.py | .py | # -*- coding: utf-8 -*-
"""The DashScope TTS module."""
from ._cosyvoice_model import DashScopeCosyVoiceTTSModel
from ._model import DashScopeTTSModel
from ._realtime_model import DashScopeRealtimeTTSModel
__all__ = [
"DashScopeCosyVoiceTTSModel",
"DashScopeTTSModel",
"DashScopeRealtimeTTSModel",
]
| 13 | 314 |
agentscope | src/agentscope/tts/_dashscope/_realtime_model.py | .py | # -*- coding: utf-8 -*-
"""DashScope Realtime TTS model implementation."""
import asyncio
import base64
import threading
from typing import Any, AsyncGenerator, Literal, TYPE_CHECKING
from pydantic import BaseModel, Field
from .._tts_base import TTSModelBase
from .._tts_response import TTSResponse
from ..._logging im... | 469 | 16,665 |
agentscope | src/agentscope/tts/_dashscope/_model.py | .py | # -*- coding: utf-8 -*-
"""DashScope TTS model implementation using MultiModalConversation API."""
import base64
import io
import wave
from datetime import datetime
from typing import (
Any,
AsyncGenerator,
Generator,
Literal,
TYPE_CHECKING,
)
from pydantic import BaseModel, Field
from .._tts_base... | 253 | 8,784 |
agentscope | src/agentscope/tts/_dashscope/_cosyvoice_utils.py | .py | # -*- coding: utf-8 -*-
"""Shared helpers for DashScope CosyVoice TTS models."""
import asyncio
import base64
import threading
from typing import Any, AsyncGenerator, TYPE_CHECKING
from .._tts_response import TTSResponse
from ..._logging import logger
from ..._utils._audio import _build_streaming_wav_header
from ...me... | 158 | 5,347 |
agentscope | src/agentscope/types/_hook.py | .py | # -*- coding: utf-8 -*-
"""The agent hooks types."""
from typing import Literal
AgentHookTypes = (
str
| Literal[
"pre_reply",
"post_reply",
"pre_print",
"post_print",
"pre_observe",
"post_observe",
]
)
ReActAgentHookTypes = (
AgentHookTypes
| Litera... | 26 | 427 |
agentscope | src/agentscope/types/__init__.py | .py | # -*- coding: utf-8 -*-
"""The types in agentscope"""
from ._hook import (
AgentHookTypes,
ReActAgentHookTypes,
)
from ._object import Embedding
from ._json import (
JSONPrimitive,
JSONSerializableObject,
)
from ._reply import (
ReplyFinishedReason,
ErrorType,
ErrorInfo,
)
__all__ = [
... | 29 | 496 |
agentscope | src/agentscope/types/_reply.py | .py | # -*- coding: utf-8 -*-
"""Reply-termination vocabulary shared by the ``message`` and ``event``
modules. Lives in ``types`` (a leaf) so both can depend on it downward
without an import cycle."""
from enum import StrEnum
from pydantic import BaseModel
class ReplyFinishedReason(StrEnum):
"""The reason a reply fini... | 53 | 1,790 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.