mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-12-03 09:53:45 +00:00
Merge 3b3a2d0ceb into 91f1b352b4
This commit is contained in:
commit
62839a91d8
9 changed files with 510 additions and 229 deletions
|
|
@ -35,6 +35,7 @@ distribution_spec:
|
|||
- provider_type: inline::code-scanner
|
||||
agents:
|
||||
- provider_type: inline::meta-reference
|
||||
- provider_type: inline::dana
|
||||
post_training:
|
||||
- provider_type: inline::torchtune-cpu
|
||||
eval:
|
||||
|
|
|
|||
|
|
@ -174,6 +174,18 @@ providers:
|
|||
backend: sql_default
|
||||
max_write_queue_size: 10000
|
||||
num_writers: 4
|
||||
- provider_id: dana
|
||||
provider_type: inline::dana
|
||||
config:
|
||||
persistence:
|
||||
agent_state:
|
||||
namespace: agents
|
||||
backend: kv_default
|
||||
responses:
|
||||
table_name: responses
|
||||
backend: sql_default
|
||||
max_write_queue_size: 10000
|
||||
num_writers: 4
|
||||
post_training:
|
||||
- provider_id: torchtune-cpu
|
||||
provider_type: inline::torchtune-cpu
|
||||
|
|
|
|||
|
|
@ -127,7 +127,10 @@ def get_distribution_template(name: str = "starter") -> DistributionTemplate:
|
|||
BuildProvider(provider_type="inline::llama-guard"),
|
||||
BuildProvider(provider_type="inline::code-scanner"),
|
||||
],
|
||||
"agents": [BuildProvider(provider_type="inline::meta-reference")],
|
||||
"agents": [
|
||||
BuildProvider(provider_type="inline::meta-reference"),
|
||||
BuildProvider(provider_type="inline::dana"),
|
||||
],
|
||||
"post_training": [BuildProvider(provider_type="inline::torchtune-cpu")],
|
||||
"eval": [BuildProvider(provider_type="inline::meta-reference")],
|
||||
"datasetio": [
|
||||
|
|
|
|||
34
src/llama_stack/providers/inline/agents/dana/__init__.py
Normal file
34
src/llama_stack/providers/inline/agents/dana/__init__.py
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
# All rights reserved.
|
||||
#
|
||||
# This source code is licensed under the terms described in the LICENSE file in
|
||||
# the root directory of this source tree.
|
||||
|
||||
from typing import Any
|
||||
|
||||
from llama_stack.core.datatypes import AccessRule, Api
|
||||
|
||||
from .config import DanaAgentsImplConfig
|
||||
|
||||
|
||||
async def get_provider_impl(
|
||||
config: DanaAgentsImplConfig,
|
||||
deps: dict[Api, Any],
|
||||
policy: list[AccessRule],
|
||||
telemetry_enabled: bool = False,
|
||||
):
|
||||
from .agents import DanaAgentsImpl
|
||||
|
||||
impl = DanaAgentsImpl(
|
||||
config,
|
||||
deps[Api.inference],
|
||||
deps[Api.vector_io],
|
||||
deps[Api.safety],
|
||||
deps[Api.tool_runtime],
|
||||
deps[Api.tool_groups],
|
||||
deps[Api.conversations],
|
||||
policy,
|
||||
telemetry_enabled,
|
||||
)
|
||||
await impl.initialize()
|
||||
return impl
|
||||
122
src/llama_stack/providers/inline/agents/dana/agents.py
Normal file
122
src/llama_stack/providers/inline/agents/dana/agents.py
Normal file
|
|
@ -0,0 +1,122 @@
|
|||
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
# All rights reserved.
|
||||
#
|
||||
# This source code is licensed under the terms described in the LICENSE file in
|
||||
# the root directory of this source tree.
|
||||
|
||||
from collections.abc import AsyncIterator
|
||||
|
||||
from llama_stack.apis.agents import (
|
||||
Agents,
|
||||
ListOpenAIResponseInputItem,
|
||||
ListOpenAIResponseObject,
|
||||
OpenAIDeleteResponseObject,
|
||||
OpenAIResponseInput,
|
||||
OpenAIResponseInputTool,
|
||||
OpenAIResponseObject,
|
||||
OpenAIResponseObjectStream,
|
||||
Order,
|
||||
)
|
||||
from llama_stack.apis.agents.agents import ResponseGuardrail
|
||||
from llama_stack.apis.agents.openai_responses import OpenAIResponsePrompt, OpenAIResponseText
|
||||
from llama_stack.apis.conversations import Conversations
|
||||
from llama_stack.apis.inference import Inference
|
||||
from llama_stack.apis.safety import Safety
|
||||
from llama_stack.apis.tools import ToolGroups, ToolRuntime
|
||||
from llama_stack.apis.vector_io import VectorIO
|
||||
from llama_stack.core.datatypes import AccessRule
|
||||
from llama_stack.log import get_logger
|
||||
|
||||
from .config import DanaAgentsImplConfig
|
||||
|
||||
logger = get_logger(name=__name__, category="agents::dana")
|
||||
|
||||
|
||||
class DanaAgentsImpl(Agents):
|
||||
"""Stub implementation of the Agents API using the Dana library."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
config: DanaAgentsImplConfig,
|
||||
inference_api: Inference,
|
||||
vector_io_api: VectorIO,
|
||||
safety_api: Safety,
|
||||
tool_runtime_api: ToolRuntime,
|
||||
tool_groups_api: ToolGroups,
|
||||
conversations_api: Conversations,
|
||||
policy: list[AccessRule],
|
||||
telemetry_enabled: bool = False,
|
||||
):
|
||||
self.config = config
|
||||
self.inference_api = inference_api
|
||||
self.vector_io_api = vector_io_api
|
||||
self.safety_api = safety_api
|
||||
self.tool_runtime_api = tool_runtime_api
|
||||
self.tool_groups_api = tool_groups_api
|
||||
self.conversations_api = conversations_api
|
||||
self.telemetry_enabled = telemetry_enabled
|
||||
self.policy = policy
|
||||
|
||||
async def initialize(self) -> None:
|
||||
"""Initialize the Dana agents implementation."""
|
||||
# TODO: Initialize Dana library here
|
||||
logger.info("Dana agents implementation initialized (stub)")
|
||||
|
||||
async def shutdown(self) -> None:
|
||||
"""Shutdown the Dana agents implementation."""
|
||||
# TODO: Cleanup Dana library here
|
||||
pass
|
||||
|
||||
# OpenAI responses
|
||||
async def get_openai_response(
|
||||
self,
|
||||
response_id: str,
|
||||
) -> OpenAIResponseObject:
|
||||
"""Get a model response."""
|
||||
raise NotImplementedError("Dana provider is not yet implemented")
|
||||
|
||||
async def create_openai_response(
|
||||
self,
|
||||
input: str | list[OpenAIResponseInput],
|
||||
model: str,
|
||||
prompt: OpenAIResponsePrompt | None = None,
|
||||
instructions: str | None = None,
|
||||
previous_response_id: str | None = None,
|
||||
conversation: str | None = None,
|
||||
store: bool | None = True,
|
||||
stream: bool | None = False,
|
||||
temperature: float | None = None,
|
||||
text: OpenAIResponseText | None = None,
|
||||
tools: list[OpenAIResponseInputTool] | None = None,
|
||||
include: list[str] | None = None,
|
||||
max_infer_iters: int | None = 10,
|
||||
guardrails: list[ResponseGuardrail] | None = None,
|
||||
) -> OpenAIResponseObject | AsyncIterator[OpenAIResponseObjectStream]:
|
||||
"""Create a model response."""
|
||||
raise NotImplementedError("Dana provider is not yet implemented")
|
||||
|
||||
async def list_openai_responses(
|
||||
self,
|
||||
after: str | None = None,
|
||||
limit: int | None = 50,
|
||||
model: str | None = None,
|
||||
order: Order | None = Order.desc,
|
||||
) -> ListOpenAIResponseObject:
|
||||
"""List all responses."""
|
||||
raise NotImplementedError("Dana provider is not yet implemented")
|
||||
|
||||
async def list_openai_response_input_items(
|
||||
self,
|
||||
response_id: str,
|
||||
after: str | None = None,
|
||||
before: str | None = None,
|
||||
include: list[str] | None = None,
|
||||
limit: int | None = 20,
|
||||
order: Order | None = Order.desc,
|
||||
) -> ListOpenAIResponseInputItem:
|
||||
"""List input items."""
|
||||
raise NotImplementedError("Dana provider is not yet implemented")
|
||||
|
||||
async def delete_openai_response(self, response_id: str) -> OpenAIDeleteResponseObject:
|
||||
"""Delete a response."""
|
||||
raise NotImplementedError("Dana provider is not yet implemented")
|
||||
38
src/llama_stack/providers/inline/agents/dana/config.py
Normal file
38
src/llama_stack/providers/inline/agents/dana/config.py
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
# All rights reserved.
|
||||
#
|
||||
# This source code is licensed under the terms described in the LICENSE file in
|
||||
# the root directory of this source tree.
|
||||
|
||||
from typing import Any
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from llama_stack.core.storage.datatypes import KVStoreReference, ResponsesStoreReference
|
||||
|
||||
|
||||
class AgentPersistenceConfig(BaseModel):
|
||||
"""Nested persistence configuration for agents."""
|
||||
|
||||
agent_state: KVStoreReference
|
||||
responses: ResponsesStoreReference
|
||||
|
||||
|
||||
class DanaAgentsImplConfig(BaseModel):
|
||||
persistence: AgentPersistenceConfig
|
||||
|
||||
@classmethod
|
||||
def sample_run_config(cls, __distro_dir__: str) -> dict[str, Any]:
|
||||
return {
|
||||
"persistence": {
|
||||
"agent_state": KVStoreReference(
|
||||
backend="kv_default",
|
||||
namespace="agents",
|
||||
).model_dump(exclude_none=True),
|
||||
"responses": ResponsesStoreReference(
|
||||
backend="sql_default",
|
||||
table_name="responses",
|
||||
).model_dump(exclude_none=True),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -38,4 +38,23 @@ def available_providers() -> list[ProviderSpec]:
|
|||
],
|
||||
description="Meta's reference implementation of an agent system that can use tools, access vector databases, and perform complex reasoning tasks.",
|
||||
),
|
||||
InlineProviderSpec(
|
||||
api=Api.agents,
|
||||
provider_type="inline::dana",
|
||||
pip_packages=[
|
||||
"dana",
|
||||
]
|
||||
+ kvstore_dependencies(), # TODO make this dynamic based on the kvstore config
|
||||
module="llama_stack.providers.inline.agents.dana",
|
||||
config_class="llama_stack.providers.inline.agents.dana.DanaAgentsImplConfig",
|
||||
api_dependencies=[
|
||||
Api.inference,
|
||||
Api.safety,
|
||||
Api.vector_io,
|
||||
Api.tool_runtime,
|
||||
Api.tool_groups,
|
||||
Api.conversations,
|
||||
],
|
||||
description="Dana library implementation of an agent system (stub).",
|
||||
),
|
||||
]
|
||||
|
|
|
|||
6
tests/unit/providers/inline/agents/dana/__init__.py
Normal file
6
tests/unit/providers/inline/agents/dana/__init__.py
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
# All rights reserved.
|
||||
#
|
||||
# This source code is licensed under the terms described in the LICENSE file in
|
||||
# the root directory of this source tree.
|
||||
|
||||
46
tests/unit/providers/inline/agents/dana/test_dana.py
Normal file
46
tests/unit/providers/inline/agents/dana/test_dana.py
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
# All rights reserved.
|
||||
#
|
||||
# This source code is licensed under the terms described in the LICENSE file in
|
||||
# the root directory of this source tree.
|
||||
|
||||
"""
|
||||
Test suite for the Dana agent provider implementation (stub).
|
||||
|
||||
TODO: Add tests when implementation is complete.
|
||||
"""
|
||||
|
||||
from llama_stack.core.datatypes import Api
|
||||
from llama_stack.core.distribution import get_provider_registry
|
||||
from llama_stack.providers.inline.agents.dana.agents import DanaAgentsImpl
|
||||
from llama_stack.providers.inline.agents.dana.config import DanaAgentsImplConfig
|
||||
|
||||
|
||||
def test_dana_provider_in_registry():
|
||||
"""Test that the Dana provider is registered and can be found in the registry."""
|
||||
provider_registry = get_provider_registry()
|
||||
agents_providers = provider_registry.get(Api.agents, {})
|
||||
|
||||
# Verify the provider is in the registry
|
||||
assert "inline::dana" in agents_providers, "Dana provider should be registered"
|
||||
|
||||
provider_spec = agents_providers["inline::dana"]
|
||||
assert provider_spec.provider_type == "inline::dana"
|
||||
assert provider_spec.api == Api.agents
|
||||
assert provider_spec.module == "llama_stack.providers.inline.agents.dana"
|
||||
assert provider_spec.config_class == "llama_stack.providers.inline.agents.dana.DanaAgentsImplConfig"
|
||||
|
||||
|
||||
def test_dana_provider_config():
|
||||
"""Test that the Dana provider config can be instantiated."""
|
||||
config = DanaAgentsImplConfig.sample_run_config(__distro_dir__="test")
|
||||
assert isinstance(config, dict)
|
||||
assert "persistence" in config
|
||||
assert "agent_state" in config["persistence"]
|
||||
assert "responses" in config["persistence"]
|
||||
|
||||
|
||||
def test_dana_provider_class_exists():
|
||||
"""Test that Dana provider class exists."""
|
||||
assert DanaAgentsImpl is not None
|
||||
# TODO: Add actual tests when the provider is implemented
|
||||
Loading…
Add table
Add a link
Reference in a new issue