Expose runtime/session metadata and document ModelAdapter & suspend#54
Merged
JohnRichard4096 merged 4 commits intomainfrom Apr 22, 2026
Merged
Expose runtime/session metadata and document ModelAdapter & suspend#54JohnRichard4096 merged 4 commits intomainfrom
JohnRichard4096 merged 4 commits intomainfrom
Conversation
Contributor
Reviewer's GuideAdds 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_completionsequenceDiagram
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
Class diagram for ModelAdapter and AdapterManagerclassDiagram
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
Class diagram for ChatObject and SessionData updatesclassDiagram
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
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Member
Author
|
@sourcery-ai title |
Deploying amritacore with
|
| Latest commit: |
edb666d
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://0e82b6e9.amritacore.pages.dev |
| Branch Preview URL: | https://feat-docs-and-fun.amritacore.pages.dev |
Contributor
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- In the new embedding docs (EN/zh) you describe
ADAPTER_TYPEasLiteral["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
ModelAdapterclass definition snippet in the new API docs is misleading because it both importsModelAdapterfromamrita_core.protocoland then redefinesclass ModelAdapterlocally, and also referencesget_configwithout 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_callingfield is only ever set and never cleared or documented; if it’s intended for external inspection, consider resetting it (e.g., toNoneafter 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>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary by Sourcery
Document embedding adapter support and suspend/resume architecture, and expose new runtime/session metadata in the core API.
Enhancements:
Documentation:
Chores: