Skip to content

Expose runtime/session metadata and document ModelAdapter & suspend#54

Merged
JohnRichard4096 merged 4 commits intomainfrom
feat/docs-and-fun
Apr 22, 2026
Merged

Expose runtime/session metadata and document ModelAdapter & suspend#54
JohnRichard4096 merged 4 commits intomainfrom
feat/docs-and-fun

Conversation

@JohnRichard4096
Copy link
Copy Markdown
Member

@JohnRichard4096 JohnRichard4096 commented Apr 22, 2026

Summary by Sourcery

Document embedding adapter support and suspend/resume architecture, and expose new runtime/session metadata in the core API.

Enhancements:

  • Expose current internal method name on ChatObject for runtime monitoring.
  • Extend SessionData with an extra dict for arbitrary session-associated data.
  • Simplify suspend_with_tag decorator implementation and relax constant string typing for core prompt templates.

Documentation:

  • Add conceptual and API reference documentation for ModelAdapter and embedding adapters in both English and Chinese guides.
  • Document two-layer suspend/resume architecture, including combined usage patterns, with diagrams and examples in both English and Chinese.
  • Clarify EmbeddingChunk related components and its relationship to ModelAdapter and adapter type literals.

Chores:

  • Update documentation navigation to include ModelAdapter and SuspendObjectStream references.
  • Increment project version from 0.8.2 to 0.8.2.1.

@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented Apr 22, 2026

Reviewer's Guide

Adds and refactors documentation around embedding adapter support and suspend/resume architecture (EN + ZH), introduces ModelAdapter API reference pages and navigation links, slightly refactors suspend decorator, loosens template typing, adds per-call tracking on ChatObject, and extends SessionData with an extra metadata dict.

Sequence diagram for embedding adapter usage via call_completion

sequenceDiagram
    actor User
    participant App as Application
    participant PM as PresetManager
    participant AM as AdapterManager
    participant MA as ModelAdapter

    User->>App: Request embeddings(texts)
    App->>PM: get_preset(embedding-preset)
    PM-->>App: ModelPreset(protocol, model, type=embed)
    App->>AM: get_adapter(ModelPreset.protocol)
    AM-->>App: ModelAdapter subclass
    App->>MA: call_embed(texts)
    MA-->>App: Sequence[EmbeddingChunk]
    App-->>User: EmbeddingChunk results
Loading

Class diagram for ModelAdapter and AdapterManager

classDiagram
    class ModelPreset
    class AmritaConfig
    class EmbeddingChunk{
        +Sequence~float~ embedding
        +int index
    }
    class ToolCall
    class UniResponse~TContent,TTools~{
        +TContent content
        +TTools tool_calls
    }
    class ModelAdapter{
        <<dataclass>>
        +ModelPreset preset
        +AmritaConfig config
        +bool __override__
        +static get_adapter_protocol() str or tuple~str~
        +static get_type() str or tuple~str~
        +call_api(messages, kwargs) AsyncGenerator
        +call_tools(messages, tools, tool_choice) UniResponse~None,list~ToolCall~~
        +call_embed(texts, kwargs) Sequence~EmbeddingChunk~
        +protocol str or tuple~str~
    }
    class AdapterManager{
        +get_adapters() dict~str, type ModelAdapter~
        +safe_get_adapter(protocol) type ModelAdapter or None
        +get_adapter(protocol) type ModelAdapter
        +register_adapter(adapter) void
    }

    ModelAdapter --> ModelPreset : uses
    ModelAdapter --> AmritaConfig : uses
    ModelAdapter --> EmbeddingChunk : returns
    ModelAdapter --> ToolCall : returns
    ModelAdapter --> UniResponse : wraps results
    AdapterManager --> ModelAdapter : manages
Loading

Class diagram for ChatObject and SessionData updates

classDiagram
    class AmritaConfig
    class MultiPresetManager
    class ClientManager
    class SuspendObjectStream~T~

    class ChatObject{
        +datetime last_call
        +str or None now_calling
    }

    class SessionData{
        +str session_id
        +dict data
        +MultiPresetManager presets
        +ClientManager mcp
        +AmritaConfig config
        +dict~str, Any~ extra
    }

    class SessionsManager

    ChatObject ..|> SuspendObjectStream~RESPONSE_TYPE~
    SessionsManager --> SessionData : manages
    SessionData --> MultiPresetManager : has
    SessionData --> ClientManager : has
    SessionData --> AmritaConfig : has
Loading

File-Level Changes

Change Details Files
Document embedding adapter support under the management concepts section and align EmbeddingChunk references with the ModelAdapter-based type definition.
  • Add a new Embedding Support section to the management concepts guide with examples of implementing and using embedding adapters, including type-safety behavior.
  • Mirror the Embedding Support section in the Chinese management concepts guide with localized explanations and examples.
  • Update EmbeddingChunk API reference pages (EN/ZH) to reference ModelAdapter and the ADAPTER_TYPE literal type instead of the old ADAPTER_TYPE enum.
docs/guide/concepts/management.md
docs/zh/guide/concepts/management.md
docs/guide/api-reference/classes/EmbeddingChunk.md
docs/zh/guide/api-reference/classes/EmbeddingChunk.md
Clarify the suspend/resume architecture with a two-layer model, including how outer suspend and inner callback mechanisms combine.
  • Add an Architecture Overview subsection with a Mermaid diagram describing outer and inner suspend layers in the English suspend concepts guide.
  • Add a Combining Both Interruption Layers section with a sequence diagram and example showing coordinated use of wait_to_suspend and callbacks.
  • Mirror the architecture overview and combination sections in the Chinese suspend concepts guide with localized diagrams and code examples.
docs/guide/concepts/suspend.md
docs/zh/guide/concepts/suspend.md
Introduce ModelAdapter API reference pages in EN/ZH and wire them into the docs navigation.
  • Create detailed ModelAdapter API reference pages in English and Chinese, covering attributes, abstract methods, adapter registration, and built-in adapters.
  • Add ModelAdapter and SuspendObjectStream entries to the API reference sidebar navigation for both English and Chinese docs locales.
docs/guide/api-reference/classes/ModelAdapter.md
docs/zh/guide/api-reference/classes/ModelAdapter.md
docs/.vitepress/config.mts
Tighten and simplify core Python APIs: relax template literal typing, simplify suspend decorator, and enrich runtime metadata on sessions and chat objects.
  • Relax type annotations for abstract/prompt template strings from LiteralString to str in consts to reduce typing constraints with Jinja2 templates.
  • Simplify the suspend_with_tag decorator to a lambda wrapper delegating directly to SuspendObjectStream.suspend.
  • Track the currently executing ChatObject internal method via a now_calling field set by the monitoring decorator.
  • Extend SessionData with an extra dict field for arbitrary per-session metadata.
src/amrita_core/consts.py
src/amrita_core/streaming.py
src/amrita_core/chatmanager.py
src/amrita_core/sessions.py
Housekeeping changes for packaging and tooling metadata.
  • Bump project version from 0.8.2 to 0.8.2.1 in pyproject.toml.
  • Update package-lock.json (likely regenerated) to reflect current frontend dependencies.
pyproject.toml
package-lock.json

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@JohnRichard4096
Copy link
Copy Markdown
Member Author

@sourcery-ai title

@sourcery-ai sourcery-ai Bot changed the title Feat/docs and fun Expose runtime/session metadata and document ModelAdapter & suspend Apr 22, 2026
@cloudflare-workers-and-pages
Copy link
Copy Markdown

Deploying amritacore with  Cloudflare Pages  Cloudflare Pages

Latest commit: edb666d
Status: ✅  Deploy successful!
Preview URL: https://0e82b6e9.amritacore.pages.dev
Branch Preview URL: https://feat-docs-and-fun.amritacore.pages.dev

View logs

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue, and left some high level feedback:

  • In the new embedding docs (EN/zh) you describe ADAPTER_TYPE as Literal["text-gen", "embed"] but also document a "rerank" type; either update the type alias description or drop "rerank" from the examples to keep the docs consistent with the actual API.
  • The ModelAdapter class definition snippet in the new API docs is misleading because it both imports ModelAdapter from amrita_core.protocol and then redefines class ModelAdapter locally, and also references get_config without import; consider changing this to a minimal, copy‑pastable example that reflects the real base class signature and required imports.
  • The newly added ChatObject.now_calling field is only ever set and never cleared or documented; if it’s intended for external inspection, consider resetting it (e.g., to None after the monitored call completes) and adding a brief comment on its expected lifecycle to avoid consumers depending on stale values.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In the new embedding docs (EN/zh) you describe `ADAPTER_TYPE` as `Literal["text-gen", "embed"]` but also document a `"rerank"` type; either update the type alias description or drop `"rerank"` from the examples to keep the docs consistent with the actual API.
- The `ModelAdapter` class definition snippet in the new API docs is misleading because it both imports `ModelAdapter` from `amrita_core.protocol` and then redefines `class ModelAdapter` locally, and also references `get_config` without import; consider changing this to a minimal, copy‑pastable example that reflects the real base class signature and required imports.
- The newly added `ChatObject.now_calling` field is only ever set and never cleared or documented; if it’s intended for external inspection, consider resetting it (e.g., to `None` after the monitored call completes) and adding a brief comment on its expected lifecycle to avoid consumers depending on stale values.

## Individual Comments

### Comment 1
<location path="src/amrita_core/chatmanager.py" line_range="530" />
<code_context>
         def inner(*args, **kwargs):
             self: ChatObject = args[0]  # This is Self
             self.last_call = datetime.now(utc)
+            self.now_calling = func.__name__
             return func(*args, **kwargs)

</code_context>
<issue_to_address>
**suggestion (bug_risk):** Consider resetting `now_calling` after the monitored function finishes to avoid stale state.

Since `now_calling` is never cleared, it will incorrectly show the function as still running after it returns or raises. Wrap the call in a `try/finally` and restore `now_calling` (to `None` or the previous value for nested calls):

```python
@wraps(func)
def inner(*args, **kwargs):
    self: ChatObject = args[0]
    self.last_call = datetime.now(utc)
    prev = self.now_calling
    self.now_calling = func.__name__
    try:
        return func(*args, **kwargs)
    finally:
        self.now_calling = prev
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread src/amrita_core/chatmanager.py
@JohnRichard4096 JohnRichard4096 merged commit ec8f1e3 into main Apr 22, 2026
3 checks passed
@JohnRichard4096 JohnRichard4096 deleted the feat/docs-and-fun branch April 22, 2026 10:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant