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/app/message_bus/_base.py | .py | # -*- coding: utf-8 -*-
"""The message bus abstract base class.
The message bus is the *live* transport layer used to coordinate work
across sessions and processes. It is intentionally separate from
:class:`StorageBase`, which owns *persistent* records: storage may live
on a relational database while the bus stays on ... | 857 | 29,319 |
agentscope | src/agentscope/app/message_bus/__init__.py | .py | # -*- coding: utf-8 -*-
"""The message bus module β live transport for cross-session messages."""
from ._base import MessageBus
from ._in_memory_message_bus import InMemoryMessageBus
from ._keys import MessageBusKeys
from ._redis_message_bus import RedisMessageBus
__all__ = [
"InMemoryMessageBus",
"MessageBus... | 15 | 372 |
agentscope | src/agentscope/app/message_bus/_keys.py | .py | # -*- coding: utf-8 -*-
"""Centralised registry of message-bus key/namespace conventions used
by application-layer services.
:class:`~agentscope.app.message_bus.MessageBus` itself stays
domain-agnostic β it exposes only generic primitives
(``publish`` / ``subscribe`` / ``queue_*`` / ``log_*`` / ``registry_*``
/ ``acqu... | 351 | 13,732 |
agentscope | src/agentscope/app/message_bus/_in_memory_message_bus.py | .py | # -*- coding: utf-8 -*-
"""In-memory message bus implementation.
A pure-Python :class:`MessageBus` backed by :mod:`asyncio` primitives,
Python dicts and lists. Designed for **single-process** use β local
development, unit tests, and examples that want to avoid a Redis
dependency.
.. note::
**Not suitable for pro... | 514 | 16,487 |
agentscope | src/agentscope/app/message_bus/_redis_message_bus.py | .py | # -*- coding: utf-8 -*-
"""The Redis-backed message bus implementation."""
import asyncio
import json
import uuid
from collections.abc import AsyncGenerator
from contextlib import asynccontextmanager
from typing import Any, Callable, Self, TYPE_CHECKING
from ._base import MessageBus
if TYPE_CHECKING:
from redis.a... | 671 | 23,043 |
agentscope | src/agentscope/app/rag/__init__.py | .py | # -*- coding: utf-8 -*-
"""Service-layer RAG building blocks.
This subpackage groups every RAG-specific service-layer concept under
one roof so the user-facing import surface stays compact:
- :mod:`.blob_store` β backends storing uploaded document bytes;
- :mod:`.knowledge_base_manager` β knowledge base lifecycle and... | 93 | 2,707 |
agentscope | src/agentscope/app/rag/blob_store/_local.py | .py | # -*- coding: utf-8 -*-
"""Local filesystem implementation of :class:`BlobStoreBase`.
The backend reserves a single root directory and treats keys as
relative paths beneath it. URIs are formatted as ``local://{key}`` β
the scheme acts as a discriminator so a mixed-deployment app can route
``local://`` and ``s3://`` U... | 146 | 5,229 |
agentscope | src/agentscope/app/rag/blob_store/_base.py | .py | # -*- coding: utf-8 -*-
"""Abstract base class for blob storage backends.
A :class:`BlobStoreBase` is the byte-level home of files uploaded into
the application β knowledge base documents in v1, potentially other
binary payloads later. It is created once at app startup and shared
across requests, mirroring the lifecy... | 159 | 5,676 |
agentscope | src/agentscope/app/rag/blob_store/__init__.py | .py | # -*- coding: utf-8 -*-
"""Blob storage backends for document uploads."""
from ._base import AsyncReadable, BlobStoreBase
from ._local import LocalBlobStore
from ._s3 import S3BlobStore
__all__ = [
"AsyncReadable",
"BlobStoreBase",
"LocalBlobStore",
"S3BlobStore",
]
| 13 | 284 |
agentscope | src/agentscope/app/rag/blob_store/_s3.py | .py | # -*- coding: utf-8 -*-
"""S3-compatible implementation of :class:`BlobStoreBase`.
Works against any service that implements the S3 wire protocol β
AWS S3, MinIO, Cloudflare R2, Aliyun OSS (S3-compatible), Tencent yun COS, etc.
The discriminator is ``endpoint_url``: ``None`` means real AWS S3
(``aioboto3`` resolves th... | 277 | 11,609 |
agentscope | src/agentscope/app/rag/knowledge_base_manager/_dimension_policy.py | .py | # -*- coding: utf-8 -*-
"""Dimension policy advertised by a knowledge base manager.
The policy tells the front-end which embedding-model dimensions are
acceptable when creating a new knowledge base. It is the *capability*
side of the contract; the server still hard-validates every create
call against the same rules.
... | 155 | 5,712 |
agentscope | src/agentscope/app/rag/knowledge_base_manager/_base.py | .py | # -*- coding: utf-8 -*-
"""Abstract knowledge base manager.
The manager is the **lifecycle owner** of knowledge bases:
- it creates / lists / deletes :class:`KnowledgeBaseRecord` rows in
storage,
- it allocates / drops the matching vector store collections,
- it resolves an embedding model from the record's credent... | 303 | 10,127 |
agentscope | src/agentscope/app/rag/knowledge_base_manager/_errors.py | .py | # -*- coding: utf-8 -*-
"""Knowledge base manager exception hierarchy.
The router maps each exception to an HTTP status code in
:mod:`agentscope.app._router._knowledge_base`:
- :class:`KnowledgeBaseNotFoundError` β ``404``
- :class:`DimensionPolicyError` β ``409``
Keeping the mapping inside the router (and not... | 60 | 1,914 |
agentscope | src/agentscope/app/rag/knowledge_base_manager/__init__.py | .py | # -*- coding: utf-8 -*-
"""Knowledge base manager classes.
The manager owns the lifecycle of knowledge bases:
- creation / deletion / listing of :class:`KnowledgeBaseRecord` rows,
- allocation / drop of the matching vector store storage,
- construction of :class:`~agentscope.rag.KnowledgeBase` runtime handles
used ... | 34 | 982 |
agentscope | src/agentscope/app/rag/knowledge_base_manager/_collection_per_kb.py | .py | # -*- coding: utf-8 -*-
"""Collection-per-knowledge-base isolation strategy.
The simplest correct implementation: every knowledge base gets its own
vector store collection sized to the chosen embedding model. No
cross-KB co-location, no namespace gymnastics β collection names are
the isolation key.
Because each know... | 209 | 7,336 |
agentscope | src/agentscope/app/rag/index_worker/__main__.py | .py | # -*- coding: utf-8 -*-
"""Entry point for ``python -m agentscope.app.rag.index_worker``.
Resolves a deployment-supplied bootstrap callable from the
``AGENTSCOPE_WORKER_BOOTSTRAP`` environment variable, calls it to
obtain the concrete backends, and hands them to :func:`run_worker`.
The deployment owns the bootstrap b... | 109 | 3,632 |
agentscope | src/agentscope/app/rag/index_worker/__init__.py | .py | # -*- coding: utf-8 -*-
"""Out-of-process index worker entry point.
A worker process owns:
- a :class:`~agentscope.app._service.IndexWorker` instance, which
runs the parse β chunk β embed pipeline for one document at a time;
- an :class:`~agentscope.app._service.IndexTaskConsumer`, which
subscribes to the shared ... | 199 | 7,619 |
agentscope | src/agentscope/app/_tool/_constants.py | .py | # -*- coding: utf-8 -*-
"""Shared constants for the framework-builtin team tools.
Centralised here (rather than duplicated per-module) so contracts that
must agree across tools have exactly one source of truth. Adding a new
tool that touches the same invariant should import from here, not
redeclare the value.
"""
HAN... | 20 | 811 |
agentscope | src/agentscope/app/_tool/_team_create.py | .py | # -*- coding: utf-8 -*-
"""The TeamCreate tool β establishes a new team led by the current session."""
from pydantic import Field
from ._team_tool_base import _TeamToolBase
from ..storage import TeamData, TeamRecord
from ...message import TextBlock, ToolResultState
from ...tool import ToolChunk, ParamsBase
class _Te... | 146 | 5,198 |
agentscope | src/agentscope/app/_tool/_agent_invite.py | .py | # -*- coding: utf-8 -*-
"""The AgentInvite tool β borrows an existing agent into the leader's team.
Unlike :class:`AgentCreate`, which spawns a brand-new worker
(``source='team'``) from a :class:`SubAgentTemplate`, this tool
**borrows** a pre-existing user-owned agent by minting a fresh
team-scoped :class:`SessionReco... | 563 | 22,434 |
agentscope | src/agentscope/app/_tool/_team_say.py | .py | # -*- coding: utf-8 -*-
"""The TeamSay tool β sends a message to one or all team members."""
import json
from typing import Any
from pydantic import Field
from ._constants import HANDLE_LEN
from ._team_tool_base import _TeamToolBase
from .._bus_ops import deliver_to_inbox
from ..storage._utils import _ensure_team_mem... | 353 | 13,234 |
agentscope | src/agentscope/app/_tool/__init__.py | .py | # -*- coding: utf-8 -*-
"""Framework-builtin tools wired into team-participating agents.
These tools differ from the workspace-provided builtins (Bash, Read,
Task series, β¦) in two ways:
1. **Construction depends on app-level resources** β they bind a
:class:`StorageBase` + :class:`MessageBus` reference plus the
... | 47 | 1,998 |
agentscope | src/agentscope/app/_tool/_agent_create.py | .py | # -*- coding: utf-8 -*-
"""The AgentCreate tool β spawns a worker into the current team."""
from __future__ import annotations
import copy
import json
from typing import TYPE_CHECKING
from pydantic import Field
from ._team_tool_base import _TeamToolBase
from .._types import SubAgentTemplate
from .._bus_ops import de... | 571 | 22,540 |
agentscope | src/agentscope/app/_tool/_team_tool_base.py | .py | # -*- coding: utf-8 -*-
"""Base class shared by the team tools."""
from typing import Any, TYPE_CHECKING
from ...permission import (
PermissionBehavior,
PermissionContext,
PermissionDecision,
)
from ...tool import ToolBase
if TYPE_CHECKING:
from ..message_bus import MessageBus
from ..storage impor... | 100 | 3,356 |
agentscope | src/agentscope/app/_tool/_team_delete.py | .py | # -*- coding: utf-8 -*-
"""The TeamDelete tool β dissolves the team led by the current session."""
from ._team_tool_base import _TeamToolBase
from ...message import TextBlock, ToolResultState
from ...tool import ToolChunk, ParamsBase
class _TeamDeleteParams(ParamsBase):
"""Parameters for :class:`TeamDelete` β non... | 132 | 4,906 |
agentscope | src/agentscope/app/hub/_base.py | .py | # -*- coding: utf-8 -*-
"""The shared hub identity and lifecycle."""
import re
from typing import Any, Self
# A hub id is a path segment in the hub routes.
HUB_ID_PATTERN = re.compile(r"[a-zA-Z0-9_-]+")
class HubBase:
"""The identity and lifecycle shared by every hub implementation.
A hub is addressed by :a... | 73 | 2,437 |
agentscope | src/agentscope/app/hub/__init__.py | .py | # -*- coding: utf-8 -*-
"""The hub classes, responsible for providing resource for the agent service.
"""
from ._base import HubBase
from ._error import HubError
from ._mcp import (
GitHubMCPHub,
MCPHubBase,
MCPCard,
MCPHubPage,
)
from ._skill import (
SkillArchive,
SkillHubBase,
SkillCard,... | 34 | 573 |
agentscope | src/agentscope/app/hub/_error.py | .py | # -*- coding: utf-8 -*-
"""The failure shared by every hub."""
class HubError(Exception):
"""Raised when a hub's upstream registry returns a failure.
One type for every hub: the registries differ but the failure does
not, and a caller that wants to map an upstream 429 onto a 503 has
to catch somethin... | 30 | 1,066 |
agentscope | src/agentscope/app/hub/_mcp/_base.py | .py | # -*- coding: utf-8 -*-
"""The MCP hub base class."""
from abc import ABC, abstractmethod
from ._card import MCPCard, MCPHubPage
from .._base import HubBase
class MCPHubBase(HubBase, ABC):
"""The base class for MCP hub implementations.
A hub exposes a browsable catalog of :class:`MCPCard` templates.
Tur... | 70 | 2,110 |
agentscope | src/agentscope/app/hub/_mcp/_card.py | .py | # -*- coding: utf-8 -*-
"""The MCP card models."""
from typing import Literal, Self
from pydantic import BaseModel, Field, model_validator
from ....mcp import StdioMCPConfig, HttpMCPConfig
class MCPCard(BaseModel):
"""A single MCP listing on a hub.
A card is a *template*, not a connectable client:
:att... | 196 | 5,754 |
agentscope | src/agentscope/app/hub/_mcp/__init__.py | .py | # -*- coding: utf-8 -*-
"""The MCP Hub classes."""
from ._base import MCPHubBase
from ._card import MCPCard, MCPHubPage
from ._github_hub import GitHubMCPHub
__all__ = [
"GitHubMCPHub",
"MCPHubBase",
"MCPCard",
"MCPHubPage",
]
| 14 | 245 |
agentscope | src/agentscope/app/hub/_mcp/_github_hub.py | .py | # -*- coding: utf-8 -*-
"""The GitHub MCP Registry provider.
A thin async client around GitHub's MCP registry
(``https://api.mcp.github.com``), exposing its servers through the
:class:`~agentscope.app.hub._mcp._base.MCPHubBase` interface.
.. note:: The registry is public and needs no credentials. A GitHub token
o... | 468 | 16,033 |
agentscope | src/agentscope/app/hub/_skill/_claw_hub.py | .py | # -*- coding: utf-8 -*-
"""The ClawHub skill provider.
A thin async client around the ClawHub HTTP API (``https://clawhub.ai``)
that exposes the registry skills through the
:class:`~agentscope.app.hub._skill._base.SkillHubBase` interface.
`ClawHub HTTP API <https://clawhub.ai/api/v1/openapi.json>`_
.. note:: Only th... | 649 | 23,200 |
agentscope | src/agentscope/app/hub/_skill/_base.py | .py | # -*- coding: utf-8 -*-
"""The skill hub base class."""
from abc import ABC, abstractmethod
from typing import AsyncIterator, Literal, NamedTuple
from ._card import SkillCard, SkillHubPage
from .._base import HubBase
class SkillArchive(NamedTuple):
"""A skill archive as the hub serves it.
The format travels... | 126 | 4,036 |
agentscope | src/agentscope/app/hub/_skill/_card.py | .py | # -*- coding: utf-8 -*-
"""The skill card models."""
from typing import Self
from pydantic import BaseModel, Field, model_validator
class SkillCard(BaseModel):
"""A single skill listing on a hub.
Unlike an :class:`MCPCard` there is nothing to configure: installing
a skill copies its files into the works... | 153 | 4,195 |
agentscope | src/agentscope/app/hub/_skill/__init__.py | .py | # -*- coding: utf-8 -*-
"""The skill hub classes."""
from ._base import SkillArchive, SkillHubBase
from ._card import SkillCard, SkillHubPage
from ._claw_hub import ClawSkillHub
__all__ = [
"SkillArchive",
"SkillHubBase",
"SkillCard",
"SkillHubPage",
"ClawSkillHub",
]
| 15 | 291 |
agentscope | src/agentscope/app/middleware/__init__.py | .py | # -*- coding: utf-8 -*-
"""The middlewares module."""
from ._inbox_middleware import InboxMiddleware
from ._protocol import ProtocolMiddlewareBase, AGUIProtocolMiddleware
from ._state_change_middleware import StateChangeMiddleware
from ._tool_offload_middleware import ToolOffloadMiddleware
__all__ = [
"InboxMidd... | 17 | 449 |
agentscope | src/agentscope/app/middleware/_tool_offload_middleware.py | .py | # -*- coding: utf-8 -*-
"""Middleware that offloads long-running tool calls to background tasks.
When a tool times out, this middleware:
- Lets the underlying asyncio task keep running via
:class:`BackgroundTaskManager` (the task is **never cancelled**).
- Yields a synthetic placeholder :class:`ToolResponse` so the... | 395 | 15,030 |
agentscope | src/agentscope/app/middleware/_inbox_middleware.py | .py | # -*- coding: utf-8 -*-
"""Generic middleware that drains the message bus inbox before reasoning.
Producers push :class:`~agentscope.message.HintBlock` payloads into
the per-session inbox via :class:`~agentscope.app._message_bus.MessageBus`.
This middleware drains the inbox at the start of each reasoning step
and inje... | 137 | 4,887 |
agentscope | src/agentscope/app/middleware/_state_change_middleware.py | .py | # -*- coding: utf-8 -*-
"""Middleware that detects agent state / team changes after each tool
call and pushes a :class:`CustomEvent` notification to the session's
event stream.
Two kinds of change are detected:
- **State change** β ``tasks_context`` or ``permission_context``
modified (detected via hash comparison).... | 197 | 6,951 |
agentscope | src/agentscope/app/middleware/_protocol/_base.py | .py | # -*- coding: utf-8 -*-
"""Protocol middleware base class for converting AgentEvent stream to
various protocols."""
import json
from abc import ABC, abstractmethod
from typing import AsyncGenerator, Callable
from fastapi import Request, Response
from fastapi.responses import StreamingResponse
from starlette.middlewar... | 245 | 8,167 |
agentscope | src/agentscope/app/middleware/_protocol/__init__.py | .py | # -*- coding: utf-8 -*-
"""The middleware used for agent protocol."""
from ._base import ProtocolMiddlewareBase
from ._agui import AGUIProtocolMiddleware
__all__ = [
"ProtocolMiddlewareBase",
"AGUIProtocolMiddleware",
]
| 11 | 230 |
agentscope | src/agentscope/app/middleware/_protocol/_agui.py | .py | # -*- coding: utf-8 -*-
"""The AGUI middleware class."""
from typing import TYPE_CHECKING, Any
from starlette.types import ASGIApp
from ._base import ProtocolMiddlewareBase
from ....event import (
AgentEvent,
DataBlockDeltaEvent,
DataBlockEndEvent,
DataBlockStartEvent,
ExceedMaxItersEvent,
Ext... | 267 | 9,255 |
agentscope | src/agentscope/app/channel/_base.py | .py | # -*- coding: utf-8 -*-
"""Channel base abstractions: events, capability, and the channel base.
A channel has exactly three concerns: keep a long-lived connection,
normalise platform payloads into :class:`ChannelEvent` /
:class:`ChannelConfirmationResultEvent` and emit them, and send the
gateway's outbound instruction... | 439 | 15,054 |
agentscope | src/agentscope/app/channel/_decision.py | .py | # -*- coding: utf-8 -*-
"""Stateless tool-approval resume.
The awaiting confirmation is read straight from the session state (the
single source of truth) and the run is resumed with the decision β no
server-side pending record. A decision that no longer matches an
ASKING tool call (stale click, double click) is ignore... | 103 | 3,215 |
agentscope | src/agentscope/app/channel/_errors.py | .py | # -*- coding: utf-8 -*-
"""Channel module exception."""
class ChannelError(Exception):
"""A channel operation failed.
Carries the HTTP status the router should surface, so one exception
covers every case (not-found β 404, duplicate bot β 409, bad request
β 400) without a subclass per case β the route... | 24 | 785 |
agentscope | src/agentscope/app/channel/__init__.py | .py | # -*- coding: utf-8 -*-
"""Channel module β connect AgentScope agents to IM platforms.
Channels translate a platform (Feishu, ...) to/from normalised events;
the stateless :class:`ChannelGateway` orchestrates each event;
:class:`~agentscope.app._service.ChannelService` owns CRUD;
:class:`ChannelLifecycleDispatcher` ke... | 40 | 1,114 |
agentscope | src/agentscope/app/channel/_routing.py | .py | # -*- coding: utf-8 -*-
"""Pure routing: resolve an inbound event to ``(agent_id, session_id)``.
There is no persisted channelβsession mapping table. Given the routing
rules on the channel record, both the target agent and the session id
are computed deterministically from the event β so every node derives
the same re... | 75 | 2,685 |
agentscope | src/agentscope/app/channel/_gateway.py | .py | # -*- coding: utf-8 -*-
"""ChannelGateway β inbound-only orchestration (data plane).
``process(event, channel)`` is the single entry point for both inbound
messages and confirmation-card clicks. It is deliberately thin:
- a **message** is routed to an ``(agent_id, session_id)`` and delivered
as run input (a user tu... | 296 | 11,005 |
agentscope | src/agentscope/app/channel/_dispatcher.py | .py | # -*- coding: utf-8 -*-
"""ChannelLifecycleDispatcher β reconcile running instances with storage.
One per node. Storage is the source of truth; this dispatcher makes the
node's live channel set match the enabled records, driven by lifecycle
notifications and a periodic sweep (which also self-heals lost
notifications a... | 425 | 15,767 |
agentscope | src/agentscope/app/channel/_registry.py | .py | # -*- coding: utf-8 -*-
"""Channel type registry β the set of platform types a service allows.
A channel *type* is fully described by its channel class (see
:class:`~agentscope.app.channel.ChannelBase`): the class carries its
``channel_type`` id, ``platform_bot_id_field``, and nested
``Credentials`` / ``Config`` model... | 167 | 5,696 |
agentscope | src/agentscope/app/channel/_discord/_channel.py | .py | # -*- coding: utf-8 -*-
"""Discord channel (discord.py, gateway WebSocket).
discord.py is async-native and runs on the app event loop, so β unlike
Feishu β there is no thread bridging: ``on_message`` and button callbacks
``await self._emit(...)`` directly. On a button click the channel freezes
its own card and emits a... | 527 | 18,158 |
agentscope | src/agentscope/app/channel/_discord/__init__.py | .py | # -*- coding: utf-8 -*-
"""Discord channel."""
from ._channel import DiscordChannel
__all__ = ["DiscordChannel"]
| 6 | 114 |
agentscope | src/agentscope/app/channel/_feishu/_channel.py | .py | # -*- coding: utf-8 -*-
"""Feishu (Lark) channel β new ChannelBase interface.
Translates the Feishu platform to/from normalised events and emits them
via the injected gateway callback. On a card click the channel freezes
its own card and emits a ``ChannelConfirmationResultEvent`` (same entry
as messages) carrying the ... | 1,323 | 46,962 |
agentscope | src/agentscope/app/channel/_feishu/__init__.py | .py | # -*- coding: utf-8 -*-
"""Feishu (Lark) channel."""
from ._channel import FeishuChannel
__all__ = ["FeishuChannel"]
| 6 | 118 |
agentscope | src/agentscope/app/channel/_feishu/_card_templates.py | .py | # -*- coding: utf-8 -*-
"""Feishu interactive-card helpers for the tool-approval flow.
The card round-trips lookup keys (``tool_call_id``, ``chat_id`` and the
resolved ``agent_id`` / ``session_id``) plus the click's approve/deny β
the authoritative tool call is read from session state on resume, never
trusted from the... | 214 | 6,762 |
agentscope | src/agentscope/app/channel/_feishu/_tools/_send_message.py | .py | # -*- coding: utf-8 -*-
"""SendMessage β send text to another Feishu chat/user."""
from pydantic import Field
from .....tool import ParamsBase, ToolChunk
from ._base import _FeishuToolBase, _ack
class _SendMessageParams(ParamsBase):
receive_id: str = Field(
description="Target id, taken verbatim from a L... | 63 | 2,123 |
agentscope | src/agentscope/app/channel/_feishu/_tools/_base.py | .py | # -*- coding: utf-8 -*-
"""Shared base and reply helper for the Feishu agent tools."""
from typing import Any, TYPE_CHECKING
from .....message import TextBlock, ToolResultState
from .....permission import (
PermissionBehavior,
PermissionContext,
PermissionDecision,
)
from .....tool import BackendBase, Tool... | 80 | 2,607 |
agentscope | src/agentscope/app/channel/_feishu/_tools/_send_image.py | .py | # -*- coding: utf-8 -*-
"""SendImage β upload and send a workspace image, rendered inline."""
from pydantic import Field
from .....message import TextBlock, ToolResultState
from .....tool import ParamsBase, ToolChunk
from ._base import _FeishuToolBase, _ack
class _SendImageParams(ParamsBase):
path: str = Field(
... | 72 | 2,483 |
agentscope | src/agentscope/app/channel/_feishu/_tools/__init__.py | .py | # -*- coding: utf-8 -*-
"""Feishu agent tools, one per module.
Two families forming a closed chain: **discovery** (``ListChats`` /
``ListChatMembers``) hands back a ``receive_id`` + ``receive_id_type``
pair that **send** (``SendMessage`` / ``SendFile`` / ``SendImage``)
consumes to reach a chat/user other than the curr... | 22 | 639 |
agentscope | src/agentscope/app/channel/_feishu/_tools/_list_chats.py | .py | # -*- coding: utf-8 -*-
"""ListChats β discover the bot's Feishu groups as address pairs."""
import json
from pydantic import Field
from .....message import TextBlock
from .....tool import ParamsBase, ToolChunk
from ._base import _FeishuToolBase
class _ListChatsParams(ParamsBase):
query: str | None = Field(
... | 59 | 1,948 |
agentscope | src/agentscope/app/channel/_feishu/_tools/_send_file.py | .py | # -*- coding: utf-8 -*-
"""SendFile β upload and send a workspace file to another chat/user."""
from pathlib import Path
from pydantic import Field
from .....message import TextBlock, ToolResultState
from .....tool import ParamsBase, ToolChunk
from ._base import _FeishuToolBase, _ack
class _SendFileParams(ParamsBas... | 79 | 2,640 |
agentscope | src/agentscope/app/channel/_feishu/_tools/_list_chat_members.py | .py | # -*- coding: utf-8 -*-
"""ListChatMembers β discover a group's members as address pairs."""
import json
from pydantic import Field
from .....message import TextBlock
from .....tool import ParamsBase, ToolChunk
from ._base import _FeishuToolBase
class _ListChatMembersParams(ParamsBase):
chat_id: str = Field(
... | 54 | 1,788 |
agentscope | src/agentscope/app/_service/_index_worker.py | .py | # -*- coding: utf-8 -*-
"""Background indexing pipeline for one knowledge document.
The :class:`IndexWorker` owns the post-upload half of the document
lifecycle. Given a ``document_id`` it:
1. acquires the processing lease via storage CAS (so only one worker
in the cluster handles the document at a time);
2. read... | 535 | 20,131 |
agentscope | src/agentscope/app/_service/_session_projection.py | .py | # -*- coding: utf-8 -*-
"""Generic cross-session UI projection primitive.
A *projection* mirrors a UI card owned by one session onto another
session's event stream, so a client subscribed only to the target
session can render and resolve it. The canonical use is team HITL: a
worker (member) session parks on a tool cal... | 187 | 6,711 |
agentscope | src/agentscope/app/_service/_channel.py | .py | # -*- coding: utf-8 -*-
"""ChannelService β stateless CRUD for channel records.
Validates, writes the record, and publishes a lifecycle notification so
every node's :class:`ChannelLifecycleDispatcher` reconciles its running
instances against storage. Holds no channel instances.
"""
from datetime import datetime
from ... | 180 | 5,932 |
agentscope | src/agentscope/app/_service/_errors.py | .py | # -*- coding: utf-8 -*-
"""Classify a fatal reply exception into a UI-facing :class:`ErrorInfo`.
Provider-agnostic: classification keys off HTTP status codes and exception
class names, walking the ``__cause__`` / ``__context__`` chain (AgentScope
often wraps a provider error one layer deep). No provider SDK is importe... | 178 | 6,191 |
agentscope | src/agentscope/app/_service/_index_task_consumer.py | .py | # -*- coding: utf-8 -*-
"""Single per-worker-process consumer of the shared index-task channel.
One asyncio task per worker process. Subscribes to the shared
:meth:`~agentscope.app.message_bus.MessageBusKeys.index_tasks_signal`
channel and drains the durable
:meth:`~agentscope.app.message_bus.MessageBusKeys.index_task... | 217 | 8,134 |
agentscope | src/agentscope/app/_service/__init__.py | .py | # -*- coding: utf-8 -*-
"""Service layer for the AgentScope app."""
from ._access import (
AgentView,
CredentialView,
KnowledgeBaseView,
ResourceAccessService,
)
from ._channel import ChannelService
from ._chat import ChatService
from ._embedding import get_embedding_model
from ._index_sweeper import In... | 50 | 1,371 |
agentscope | src/agentscope/app/_service/_index_sweeper.py | .py | # -*- coding: utf-8 -*-
"""Background sweep for stuck knowledge-document indexing jobs.
The indexing pipeline relies on two storage-level signals to keep
moving when something goes wrong:
- a *lease* per in-flight document β its ``lease_expires_at`` is the
upper bound on how long a worker may sit on the document be... | 151 | 5,613 |
agentscope | src/agentscope/app/_service/_workspace.py | .py | # -*- coding: utf-8 -*-
"""Workspace service β resolution, download tokens, uploads, git."""
import asyncio
import base64
import hashlib
import hmac
import re
import tarfile
import time
from typing import AsyncIterator, Literal
from fastapi import HTTPException, UploadFile, status
from pydantic import BaseModel, Field... | 716 | 25,061 |
agentscope | src/agentscope/app/_service/_chat.py | .py | # -*- coding: utf-8 -*-
"""Chat service encapsulating agent execution + persistence logic.
This is the single source of truth for running an agent against a
session. Both the HTTP chat endpoint and the wakeup dispatcher call
:meth:`ChatService.run`, guaranteeing identical message persistence,
middleware wiring, and st... | 1,111 | 48,598 |
agentscope | src/agentscope/app/_service/_session.py | .py | # -*- coding: utf-8 -*-
"""Cross-resource session lifecycle service.
Owns the "stop in-flight runs + delete records + drop bus state"
cascades that ``DELETE /sessions/{sid}``, ``DELETE /agents/{aid}``,
``DELETE /schedules/{sid}`` and the agent-facing
:class:`~agentscope.app._tools.TeamDelete` /
:class:`~agentscope.app... | 729 | 29,523 |
agentscope | src/agentscope/app/_service/_knowledge_base.py | .py | # -*- coding: utf-8 -*-
"""Knowledge base service: HTTP-side orchestration.
The router stays thin and DTO-shaped; everything HTTP-side that needs
to coordinate persistence, the blob store, the indexing pipeline,
and the vector store goes through this service.
The split with :class:`~agentscope.rag.KnowledgeBase`
is d... | 546 | 19,543 |
agentscope | src/agentscope/app/_service/_tts_model.py | .py | # -*- coding: utf-8 -*-
"""TTS model service: builds a TTSModelBase from stored credential + config."""
from typing import Type
from fastapi import HTTPException, status
from ._access import ResourceAccessService
from ..storage import TTSModelConfig
from ...credential import CredentialFactory
from ...tts import TTSMo... | 66 | 1,926 |
agentscope | src/agentscope/app/_service/_access.py | .py | # -*- coding: utf-8 -*-
"""Resource access service β cross-owner reads with viewer-relative views."""
from __future__ import annotations
from datetime import datetime
from typing import Any, Literal, TypeVar, overload
from fastapi import HTTPException, status
from pydantic import BaseModel, Field, model_validator
fr... | 523 | 18,173 |
agentscope | src/agentscope/app/_service/_embedding.py | .py | # -*- coding: utf-8 -*-
"""Embedding model service: builds an EmbeddingModelBase from stored
credential + config.
Mirrors :mod:`._model` (which does the same for chat models).
Two entry points are provided:
- :func:`get_embedding_model` β HTTP / ChatService path. Resolves the
credential through :class:`ResourceAcc... | 127 | 4,119 |
agentscope | src/agentscope/app/_service/_model.py | .py | # -*- coding: utf-8 -*-
"""Model service: builds a ChatModelBase from stored credential + config."""
from ._access import ResourceAccessService
from ..storage import ChatModelConfig
from ...credential import CredentialFactory
from ...model import ChatModelBase
from ..._logging import logger
async def get_model(
u... | 74 | 2,379 |
agentscope | src/agentscope/app/_service/_toolkit.py | .py | # -*- coding: utf-8 -*-
"""Toolkit assembly for an (agent, session) pair.
The single entry point :func:`get_toolkit` gathers every tool source β
workspace builtins, MCPs, skills, planning tools (Task*), background-task
control (ToolStop), schedule control (Schedule*), team participation
tools, and caller-supplied extr... | 279 | 11,483 |
agentscope | src/agentscope/app/_service/_mcp_render.py | .py | # -*- coding: utf-8 -*-
"""Render an :class:`MCPCard` template into a connectable client."""
from string import Template
from typing import Any
import jsonschema
from ..hub import MCPCard
from ...mcp import MCPClient
class MCPRenderError(ValueError):
"""Raised when user-supplied values do not fit an :class:`MCP... | 169 | 5,085 |
agentscope | src/agentscope/app/_service/_projectors/_subagent_hitl.py | .py | # -*- coding: utf-8 -*-
"""Projector that bridges team-member HITL events to leader sessions.
When a team *member* (worker) session hits a tool call that needs human
confirmation, the worker run parks on an ``ASKING`` tool call in its
**own** session β invisible to a client subscribed only to the *leader*
session's ev... | 276 | 10,395 |
agentscope | src/agentscope/app/_service/_projectors/__init__.py | .py | # -*- coding: utf-8 -*-
"""Built-in event projectors.
Each projector mirrors one cross-session UI feed onto the owning
session via the shared
:class:`~agentscope.app._service._session_projection.SessionProjection`
primitive. See :class:`~agentscope.app._types.EventProjector`.
"""
from ._subagent_hitl import SubagentHi... | 14 | 376 |
agentscope | src/agentscope/app/_manager/_background_task_manager.py | .py | # -*- coding: utf-8 -*-
"""The background task manager."""
import asyncio
import json
import time
from collections import OrderedDict
from dataclasses import dataclass, field
from typing import Any, Self, TYPE_CHECKING
import shortuuid
from pydantic import BaseModel, Field
from agentscope.message import TextBlock, To... | 471 | 15,217 |
agentscope | src/agentscope/app/_manager/__init__.py | .py | # -*- coding: utf-8 -*-
"""The agent service managers, used in FastAPI lifespan to manage
application-wide resources."""
from ._scheduler import SchedulerManager
from ._wakeup_dispatcher import WakeupDispatcher
from ._cancel_dispatcher import CancelDispatcher
from ._chat_run_registry import ChatRunRegistry
from ._back... | 18 | 508 |
agentscope | src/agentscope/app/_manager/_cancel_dispatcher.py | .py | # -*- coding: utf-8 -*-
"""Single per-process dispatcher for cross-process cancels.
Subscribes to two bus channels:
1. **Session cancel** β cancel all local work for a session (chat run
+ all BG tasks). Triggered by session deletion or explicit abort.
2. **Task cancel** β cancel a single BG task by task_id. Trigge... | 247 | 8,685 |
agentscope | src/agentscope/app/_manager/_wakeup_dispatcher.py | .py | # -*- coding: utf-8 -*-
"""Single per-process dispatcher for all cross-session run triggers.
One asyncio task per process. Subscribes to the shared trigger signal
channel and drains the durable trigger queue on each signal. It is the
**sole** site that spawns :meth:`ChatService.run` into the shared
:class:`ChatRunRegi... | 415 | 15,300 |
agentscope | src/agentscope/app/_manager/_chat_run_registry.py | .py | # -*- coding: utf-8 -*-
"""Per-process registry of in-flight ``ChatService.run`` asyncio tasks.
Owns the asyncio.Task handles only β it is not the public cancel
entry point. The cross-process cancel path goes through the bus's
:meth:`~agentscope.app.message_bus.MessageBus.session_publish_cancel`
broadcast, picked up l... | 135 | 4,742 |
agentscope | src/agentscope/app/_manager/_scheduler/__init__.py | .py | # -*- coding: utf-8 -*-
"""The scheduler related components."""
from ._scheduler_manager import SchedulerManager
__all__ = [
"SchedulerManager",
]
| 9 | 153 |
agentscope | src/agentscope/app/_manager/_scheduler/_scheduler_manager.py | .py | # -*- coding: utf-8 -*-
"""The cron scheduler manager class."""
import json
from collections.abc import Callable, Coroutine
from typing import Self
from ....message import HintBlock
from ....permission import PermissionContext
from ....state import AgentState
from ....tool import ToolBase
from ...._logging import log... | 430 | 15,664 |
agentscope | src/agentscope/app/_manager/_scheduler/_tools/_schedule_create.py | .py | # -*- coding: utf-8 -*-
"""The schedule create tool."""
from datetime import datetime
from typing import Any
from pydantic import BaseModel, Field
from .....message import ToolResultState, TextBlock
from .....permission import (
PermissionContext,
PermissionDecision,
PermissionBehavior,
PermissionMode... | 254 | 9,043 |
agentscope | src/agentscope/app/_manager/_scheduler/_tools/_schedule_view.py | .py | # -*- coding: utf-8 -*-
"""The schedule view tool."""
from typing import Any
from pydantic import BaseModel, Field
from .....message import ToolResultState, TextBlock
from .....permission import (
PermissionContext,
PermissionDecision,
PermissionBehavior,
)
from .....tool import ToolBase, ToolChunk
from .... | 139 | 4,440 |
agentscope | src/agentscope/app/_manager/_scheduler/_tools/__init__.py | .py | # -*- coding: utf-8 -*-
"""The schedule related tools."""
from ._schedule_create import ScheduleCreate
from ._schedule_delete import ScheduleDelete
from ._schedule_list import ScheduleList
from ._schedule_view import ScheduleView
__all__ = [
"ScheduleCreate",
"ScheduleDelete",
"ScheduleList",
"Schedul... | 15 | 330 |
agentscope | src/agentscope/app/_manager/_scheduler/_tools/_schedule_delete.py | .py | # -*- coding: utf-8 -*-
"""Schedule delete tool β removes a job from the scheduler and storage."""
from typing import Any
from pydantic import BaseModel, Field
from apscheduler.jobstores.base import JobLookupError
from .....message import ToolResultState, TextBlock
from .....permission import (
PermissionContext,... | 155 | 5,051 |
agentscope | src/agentscope/app/_manager/_scheduler/_tools/_schedule_list.py | .py | # -*- coding: utf-8 -*-
"""The tool to list the scheduled jobs in the cron scheduler manager."""
from typing import Any
from pydantic import BaseModel
from .....message import ToolResultState, TextBlock
from .....permission import (
PermissionContext,
PermissionDecision,
PermissionBehavior,
)
from .....to... | 116 | 3,904 |
reflex | packages/hatch-reflex-pyi/src/hatch_reflex_pyi/hooks.py | .py | """Hatch plugin registration for reflex-pyi build hook."""
from hatchling.plugin import hookimpl
from hatch_reflex_pyi.plugin import ReflexPyiBuildHook
@hookimpl
def hatch_register_build_hook():
"""Register the reflex-pyi build hook.
Returns:
ReflexPyiBuildHook: The build hook class to be registere... | 16 | 362 |
reflex | packages/hatch-reflex-pyi/src/hatch_reflex_pyi/plugin.py | .py | """Hatch build hook that generates .pyi stub files for Reflex component packages."""
from __future__ import annotations
import pathlib
import subprocess
import sys
from typing import Any
from hatchling.builders.hooks.plugin.interface import BuildHookInterface
class ReflexPyiBuildHook(BuildHookInterface):
"""Bu... | 76 | 2,338 |
reflex | packages/reflex-docgen/src/reflex_docgen/_class.py | .py | """Generate documentation for arbitrary Python classes."""
import collections.abc
import dataclasses
import inspect
import re
from dataclasses import dataclass
from typing import Any, Literal, get_args, get_origin, get_type_hints
from reflex_base.utils.types import is_union
from reflex_base.vars.base import BaseState... | 611 | 19,942 |
reflex | packages/reflex-docgen/src/reflex_docgen/__init__.py | .py | """Module for generating documentation for Reflex components and classes."""
from reflex_docgen import markdown as markdown
from reflex_docgen._class import ClassDocumentation as ClassDocumentation
from reflex_docgen._class import FieldDocumentation as FieldDocumentation
from reflex_docgen._class import MethodDocument... | 36 | 1,394 |
reflex | packages/reflex-docgen/src/reflex_docgen/_component.py | .py | """Generate documentation for Reflex components."""
from dataclasses import dataclass
from typing import Any
from reflex_base.components.component import DEFAULT_TRIGGERS_AND_DESC, Component
from reflex_base.event import EventHandler
@dataclass(frozen=True, slots=True, kw_only=True)
class PropDocumentation:
"""... | 152 | 4,353 |
reflex | packages/reflex-docgen/src/reflex_docgen/markdown/__init__.py | .py | """Markdown parsing and types for Reflex documentation."""
from __future__ import annotations
from reflex_docgen.markdown import transformer as transformer
from reflex_docgen.markdown._parser import parse_document as parse_document
from reflex_docgen.markdown._types import Block as Block
from reflex_docgen.markdown._... | 60 | 2,333 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.