forked from HAL9000/cleveragents-core
docs(spec): align AIProviderInterface with implementation (generate_changes/stream_changes)
Relates to #5801 The spec defined AIProviderInterface as a model factory with create_chat_model() and create_embedding_model() methods. The implementation uses a higher-level plan-execution interface with generate_changes() and stream_changes(). The implementation's approach is more appropriate — it directly handles plan execution rather than exposing raw LangChain model creation. The ProviderRegistry manages provider selection and configuration at a higher level. Updated AIProviderInterface to match the actual implementation: - provider_name -> name (property) - capabilities -> model_id (property) - create_chat_model() -> generate_changes() (plan execution) - create_embedding_model() -> stream_changes() (streaming plan execution) Also updated the description: auto-discovery of langchain-* packages is not implemented; instead, providers are discovered based on configured API keys.
This commit is contained in:
+35
-14
@@ -46427,31 +46427,52 @@ Actors can be extended through:
|
||||
|
||||
1. **YAML-defined agents**: Single LLM actors with custom system prompts, temperature settings, tool bindings, and capability constraints.
|
||||
2. **YAML-defined graphs**: LangGraph topologies with multiple actors and tool nodes connected by edges, conditional routing, and parallel execution groups.
|
||||
3. **Provider extension**: New LLM providers can be added by implementing the `AIProviderInterface` protocol and registering with the `ProviderRegistry`. The registry uses auto-discovery to detect installed `langchain-*` packages.
|
||||
3. **Provider extension**: New LLM providers can be added by implementing the `AIProviderInterface` protocol and registering with the `ProviderRegistry`. The registry discovers configured providers based on available API keys and environment variables.
|
||||
|
||||
<div class="highlight"><pre><code><span style="color: magenta; font-weight: 600;">from</span> typing <span style="color: magenta; font-weight: 600;">import</span> <span style="color: cyan;">Protocol</span>
|
||||
<div class="highlight"><pre><code><span style="color: magenta; font-weight: 600;">from</span> collections.abc <span style="color: magenta; font-weight: 600;">import</span> <span style="color: cyan;">Callable, Iterator</span>
|
||||
<span style="color: magenta; font-weight: 600;">from</span> typing <span style="color: magenta; font-weight: 600;">import</span> <span style="color: cyan;">Protocol</span>
|
||||
|
||||
<span style="color: magenta; font-weight: 600;">class</span> <span style="color: cyan; font-weight: 600;">AIProviderInterface</span>(<span style="color: cyan;">Protocol</span>):
|
||||
<span style="color: #888;">"""Protocol for LLM provider implementations."""</span>
|
||||
<span style="color: #888;">"""Protocol for AI providers that generate code changes.
|
||||
|
||||
Implementations handle plan execution directly, generating changes
|
||||
based on the plan, project context, and actor configuration.
|
||||
Supported providers: openai, anthropic, google, gemini, azure,
|
||||
openrouter, cohere, groq, together.
|
||||
"""</span>
|
||||
|
||||
<span style="color: cyan;">@property</span>
|
||||
<span style="color: magenta; font-weight: 600;">def</span> <span style="color: cyan; font-weight: 600;">provider_name</span>(<span style="color: cyan;">self</span>) -> <span style="color: cyan;">str</span>: ...
|
||||
<span style="color: magenta; font-weight: 600;">def</span> <span style="color: cyan; font-weight: 600;">name</span>(<span style="color: cyan;">self</span>) -> <span style="color: cyan;">str</span>: ...
|
||||
<span style="color: #888;">"""Provider name (e.g., 'openai', 'anthropic')."""</span>
|
||||
|
||||
<span style="color: cyan;">@property</span>
|
||||
<span style="color: magenta; font-weight: 600;">def</span> <span style="color: cyan; font-weight: 600;">capabilities</span>(<span style="color: cyan;">self</span>) -> ProviderCapabilities: ...
|
||||
<span style="color: magenta; font-weight: 600;">def</span> <span style="color: cyan; font-weight: 600;">model_id</span>(<span style="color: cyan;">self</span>) -> <span style="color: cyan;">str</span>: ...
|
||||
<span style="color: #888;">"""Model identifier (e.g., 'gpt-4o', 'claude-3-5-sonnet-20241022')."""</span>
|
||||
|
||||
<span style="color: magenta; font-weight: 600;">def</span> <span style="color: cyan; font-weight: 600;">create_chat_model</span>(
|
||||
<span style="color: magenta; font-weight: 600;">def</span> <span style="color: cyan; font-weight: 600;">generate_changes</span>(
|
||||
<span style="color: cyan;">self</span>,
|
||||
model: <span style="color: cyan;">str</span>,
|
||||
temperature: <span style="color: cyan;">float</span> = <span style="color: yellow;">0.7</span>,
|
||||
**kwargs,
|
||||
) -> BaseChatModel: ...
|
||||
project: Project,
|
||||
plan: Plan,
|
||||
contexts: list[Context],
|
||||
actor_context: ActorInvocationContext | None = None,
|
||||
progress_callback: Callable[[int], None] | None = None,
|
||||
) -> ProviderResponse: ...
|
||||
<span style="color: #888;">"""Generate code changes based on the plan and context."""</span>
|
||||
|
||||
<span style="color: magenta; font-weight: 600;">def</span> <span style="color: cyan; font-weight: 600;">create_embedding_model</span>(
|
||||
<span style="color: magenta; font-weight: 600;">def</span> <span style="color: cyan; font-weight: 600;">stream_changes</span>(
|
||||
<span style="color: cyan;">self</span>,
|
||||
model: <span style="color: cyan;">str</span>,
|
||||
**kwargs,
|
||||
) -> BaseEmbeddings: ...
|
||||
project: Project,
|
||||
plan: Plan,
|
||||
contexts: list[Context],
|
||||
actor_context: ActorInvocationContext | None = None,
|
||||
progress_callback: Callable[[int], None] | None = None,
|
||||
) -> Iterator[dict[str, object]]: ...
|
||||
<span style="color: #888;">"""Stream workflow events while generating changes.
|
||||
|
||||
Yields dicts keyed by workflow node name. Finishes with a
|
||||
``"__end__"`` event containing a ``ProviderResponse`` under
|
||||
the ``response`` key.
|
||||
"""</span>
|
||||
</code></pre></div>
|
||||
|
||||
#### Custom Resource Types
|
||||
|
||||
Reference in New Issue
Block a user