Skip to content

Commit c93ba9f

Browse files
chore(docs): update agent, memory, and knowledgebase docstrings (#269)
1 parent 93952b5 commit c93ba9f

14 files changed

+929
-106
lines changed

veadk/a2a/remote_ve_agent.py

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,62 @@ def _convert_agent_card_dict_to_obj(agent_card_dict: dict) -> AgentCard:
3434

3535

3636
class RemoteVeAgent(RemoteA2aAgent):
37-
"""Connect to remote agent on VeFaaS platform."""
37+
"""Connect to a remote agent on the VeFaaS platform.
38+
39+
This class provides an interface to remotely connect with an agent deployed on the VeFaaS platform. It automatically fetches the agent card (metadata) and configures an HTTP client for secure communication. Authentication can be handled either via a bearer token in the HTTP header or via a query string parameter.
40+
41+
The class extends `RemoteA2aAgent` to provide compatibility with the A2A (Agent-to-Agent) communication layer.
42+
43+
This constructor connects to a remote VeFaaS agent endpoint, retrieves its metadata (`agent_card`), and sets up an asynchronous HTTP client (`httpx.AsyncClient`) for subsequent communication. Depending on the provided authentication parameters, it supports three connection modes:
44+
- **No authentication:** Directly fetches the agent card.
45+
- **Header authentication:** Sends a bearer token in the `Authorization` header.
46+
- **Query string authentication:** Appends the token to the URL query.
47+
48+
Attributes:
49+
name (str):
50+
A unique name identifying this remote agent instance.
51+
url (str):
52+
The base URL of the remote agent on the VeFaaS platform.
53+
auth_token (str | None):
54+
Optional authentication token used for secure access.
55+
If not provided, the agent will be accessed without authentication.
56+
auth_method (Literal["header", "querystring"] | None):
57+
The method of attaching the authentication token.
58+
- `"header"`: Token is passed via HTTP `Authorization` header.
59+
- `"querystring"`: Token is passed as a query parameter.
60+
- `None`: No authentication used.
61+
62+
Raises:
63+
ValueError:
64+
If an unsupported `auth_method` is provided when `auth_token` is set.
65+
requests.RequestException:
66+
If fetching the agent card from the remote URL fails.
67+
68+
Examples:
69+
```python
70+
# Example 1: No authentication
71+
agent = RemoteVeAgent(
72+
name="public_agent",
73+
url="https://vefaas.example.com/agents/public"
74+
)
75+
76+
# Example 2: Using Bearer token in header
77+
agent = RemoteVeAgent(
78+
name="secured_agent",
79+
url="https://vefaas.example.com/agents/secure",
80+
auth_token="my_secret_token",
81+
auth_method="header"
82+
)
83+
84+
# Example 3: Using token in query string
85+
agent = RemoteVeAgent(
86+
name="query_agent",
87+
url="https://vefaas.example.com/agents/query",
88+
auth_token="my_secret_token",
89+
auth_method="querystring"
90+
)
91+
```
92+
"""
3893

3994
def __init__(
4095
self,

veadk/agent.py

Lines changed: 79 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -47,55 +47,108 @@
4747

4848

4949
class Agent(LlmAgent):
50-
"""LLM-based Agent with Volcengine capabilities."""
50+
"""LLM-based Agent with Volcengine capabilities.
51+
52+
This class represents an intelligent agent powered by LLMs (Large Language Models),
53+
integrated with Volcengine's AI framework. It supports memory modules, sub-agents,
54+
tracers, knowledge bases, and other advanced features for A2A (Agent-to-Agent)
55+
or user-facing scenarios.
56+
57+
Attributes:
58+
name (str): The name of the agent.
59+
description (str): A description of the agent, useful in A2A scenarios.
60+
instruction (Union[str, InstructionProvider]): The instruction or instruction provider.
61+
model_name (str): Name of the model used by the agent.
62+
model_provider (str): Provider of the model (e.g., openai).
63+
model_api_base (str): The base URL of the model API.
64+
model_api_key (str): The API key for accessing the model.
65+
model_extra_config (dict): Extra configurations to include in model requests.
66+
tools (list[ToolUnion]): Tools available to the agent.
67+
sub_agents (list[BaseAgent]): Sub-agents managed by this agent.
68+
knowledgebase (Optional[KnowledgeBase]): Knowledge base attached to the agent.
69+
short_term_memory (Optional[ShortTermMemory]): Session-based memory for temporary context.
70+
long_term_memory (Optional[LongTermMemory]): Cross-session memory for persistent user context.
71+
tracers (list[BaseTracer]): List of tracers used for telemetry and monitoring.
72+
73+
Notes:
74+
Before creating your agent, you should get the API Key for your model.
75+
76+
Examples:
77+
### Simple agent
78+
79+
Create a simplest agent without any extra settings. All agent attributes are come from environment variables and default values. Like:
80+
81+
```python
82+
import asyncio
83+
84+
from veadk import Agent, Runner
85+
86+
root_agent = Agent()
87+
88+
runner = Runner(agent=root_agent)
89+
90+
response = asyncio.run(runner.run("hello"))
91+
print(response)
92+
```
93+
94+
You can set some agent metadata attributes by the following code:
95+
96+
```python
97+
from veadk import Agent
98+
99+
from veadk import Agent, Runner
100+
101+
root_agent = Agent(
102+
name="meeting_assistant",
103+
description="An assistant that helps user to make meetings.",
104+
# system prompt
105+
instruction="First learn about user's meeting time, location, and other key informations, and give out a meeting plan.",
106+
)
107+
```
108+
109+
Or, once you want to use your local-serving model or models from other provider, you can specify some model-related configurations in initiation arguments:
110+
111+
```python
112+
agent = Agent(model_name="", model_api_key="", model_api_base="")
113+
```
114+
115+
Besides, you can specify some extra options by ARK requirements, such as:
116+
117+
```python
118+
# disable thinking
119+
model_extra_config = {}
120+
```
121+
122+
In some systems, mulitple-agent based design is necessary, you can implement a multiple-agent system by `sub_agent` argument:
123+
124+
```python
125+
from veadk import Agent
126+
```
127+
128+
"""
51129

52130
model_config = ConfigDict(arbitrary_types_allowed=True, extra="allow")
53-
"""The model config"""
54131

55132
name: str = DEFAULT_AGENT_NAME
56-
"""The name of the agent."""
57-
58133
description: str = DEFAULT_DESCRIPTION
59-
"""The description of the agent. This will be helpful in A2A scenario."""
60-
61134
instruction: Union[str, InstructionProvider] = DEFAULT_INSTRUCTION
62-
"""The instruction for the agent."""
63135

64136
model_name: str = Field(default_factory=lambda: settings.model.name)
65-
"""The name of the model for agent running."""
66-
67137
model_provider: str = Field(default_factory=lambda: settings.model.provider)
68-
"""The provider of the model for agent running."""
69-
70138
model_api_base: str = Field(default_factory=lambda: settings.model.api_base)
71-
"""The api base of the model for agent running."""
72-
73139
model_api_key: str = Field(default_factory=lambda: settings.model.api_key)
74-
"""The api key of the model for agent running."""
75-
76140
model_extra_config: dict = Field(default_factory=dict)
77-
"""The extra config to include in the model requests."""
78141

79142
tools: list[ToolUnion] = []
80-
"""The tools provided to agent."""
81143

82144
sub_agents: list[BaseAgent] = Field(default_factory=list, exclude=True)
83-
"""The sub agents provided to agent."""
84145

85146
knowledgebase: Optional[KnowledgeBase] = None
86-
"""The knowledgebase provided to agent."""
87147

88148
short_term_memory: Optional[ShortTermMemory] = None
89-
"""The short term memory provided to agent."""
90-
91149
long_term_memory: Optional[LongTermMemory] = None
92-
"""The long term memory provided to agent.
93-
94-
In VeADK, the `long_term_memory` refers to cross-session memory under the same user.
95-
"""
96150

97151
tracers: list[BaseTracer] = []
98-
"""The tracers provided to agent."""
99152

100153
def model_post_init(self, __context: Any) -> None:
101154
super().model_post_init(None) # for sub_agents init

veadk/agents/loop_agent.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,38 @@
2929

3030

3131
class LoopAgent(GoogleADKLoopAgent):
32-
"""Loop Agent with Volcengine capabilities."""
32+
"""Loop Agent with several sub agents.
33+
34+
This agent is capable of looping through and executing all sub-agents sequentially
35+
or based on specific conditions. It is designed to operate in environments where
36+
multiple agents need to work together in a looped execution flow, such as handling
37+
complex, multi-step tasks or workflows. The agent integrates Volcengine’s AI
38+
capabilities and supports a variety of tools and tracers for enhanced functionality
39+
and performance monitoring.
40+
41+
Attributes:
42+
model_config (ConfigDict): Configuration dictionary for the model.
43+
name (str): The name of the agent, default is "veLoopAgent".
44+
description (str): A description of the agent, helpful in A2A scenarios.
45+
instruction (str): Instructions or principles for function calling and agent execution.
46+
sub_agents (list[BaseAgent]): A list of sub-agents managed by the loop agent. Each sub-agent
47+
is executed in a looped sequence based on the agent's logic.
48+
tracers (list[BaseTracer]): A list of tracers used for monitoring the agent's performance
49+
and behavior during execution.
50+
51+
Examples:
52+
53+
"""
3354

3455
model_config = ConfigDict(arbitrary_types_allowed=True, extra="allow")
35-
"""The model config"""
3656

3757
name: str = "veLoopAgent"
38-
"""The name of the agent."""
39-
4058
description: str = DEFAULT_DESCRIPTION
41-
"""The description of the agent. This will be helpful in A2A scenario."""
42-
4359
instruction: str = DEFAULT_INSTRUCTION
44-
"""The instruction for the agent, such as principles of function calling."""
4560

4661
sub_agents: list[BaseAgent] = Field(default_factory=list, exclude=True)
47-
"""The sub agents provided to agent."""
4862

4963
tracers: list[BaseTracer] = []
50-
"""The tracers provided to agent."""
5164

5265
def model_post_init(self, __context: Any) -> None:
5366
super().model_post_init(None) # for sub_agents init

veadk/agents/parallel_agent.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,37 @@
2929

3030

3131
class ParallelAgent(GoogleADKParallelAgent):
32-
"""LLM-based Agent with Volcengine capabilities."""
32+
"""LLM-based Agent that can execute sub-agents in parallel.
33+
34+
This agent is capable of executing multiple sub-agents concurrently, making it suitable
35+
for scenarios that require parallel execution of multiple tasks or operations. By leveraging
36+
parallelism, the agent can handle more complex workflows and improve efficiency by performing
37+
independent tasks simultaneously. This design is ideal for scenarios where tasks are independent
38+
and can benefit from reduced execution time.
39+
40+
Attributes:
41+
model_config (ConfigDict): Configuration dictionary for the model.
42+
name (str): The name of the agent, default is "veParallelAgent".
43+
description (str): A description of the agent, useful in A2A scenarios.
44+
instruction (str): Instructions or principles for function calling and agent execution.
45+
sub_agents (list[BaseAgent]): A list of sub-agents managed by the parallel agent.
46+
Each sub-agent is executed concurrently.
47+
tracers (list[BaseTracer]): A list of tracers used for monitoring the agent's performance
48+
and behavior during parallel execution.
49+
50+
Examples:
51+
52+
"""
3353

3454
model_config = ConfigDict(arbitrary_types_allowed=True, extra="allow")
35-
"""The model config"""
3655

3756
name: str = "veParallelAgent"
38-
"""The name of the agent."""
39-
4057
description: str = DEFAULT_DESCRIPTION
41-
"""The description of the agent. This will be helpful in A2A scenario."""
42-
4358
instruction: str = DEFAULT_INSTRUCTION
44-
"""The instruction for the agent, such as principles of function calling."""
4559

4660
sub_agents: list[BaseAgent] = Field(default_factory=list, exclude=True)
47-
"""The sub agents provided to agent."""
4861

4962
tracers: list[BaseTracer] = []
50-
"""The tracers provided to agent."""
5163

5264
def model_post_init(self, __context: Any) -> None:
5365
super().model_post_init(None) # for sub_agents init

veadk/agents/sequential_agent.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,34 @@
2929

3030

3131
class SequentialAgent(GoogleADKSequentialAgent):
32-
"""Sequential Agent with Volcengine capabilities."""
32+
"""Sequential Agent that executes sub-agents sequentially.
33+
34+
This agent is designed to execute multiple sub-agents in a predefined sequential order.
35+
It ensures that each sub-agent is executed one after the other, making it suitable for
36+
workflows where the output of one sub-agent is needed as input for the next. The agent
37+
is well-suited for tasks that require a linear progression of steps or operations, ensuring
38+
that the execution flow is maintained.
39+
40+
Attributes:
41+
model_config (ConfigDict): Configuration dictionary for the model.
42+
name (str): The name of the agent, default is "veSequentialAgent".
43+
description (str): A description of the agent, useful in A2A scenarios.
44+
instruction (str): Instructions or principles for function calling and agent execution.
45+
sub_agents (list[BaseAgent]): A list of sub-agents managed by the sequential agent.
46+
Each sub-agent is executed in the order they are listed.
47+
tracers (list[BaseTracer]): A list of tracers used for monitoring the agent's performance
48+
and behavior during sequential execution.
49+
"""
3350

3451
model_config = ConfigDict(arbitrary_types_allowed=True, extra="allow")
35-
"""The model config"""
3652

3753
name: str = "veSequentialAgent"
38-
"""The name of the agent."""
39-
4054
description: str = DEFAULT_DESCRIPTION
41-
"""The description of the agent. This will be helpful in A2A scenario."""
42-
4355
instruction: str = DEFAULT_INSTRUCTION
44-
"""The instruction for the agent, such as principles of function calling."""
4556

4657
sub_agents: list[BaseAgent] = Field(default_factory=list, exclude=True)
47-
"""The sub agents provided to agent."""
4858

4959
tracers: list[BaseTracer] = []
50-
"""The tracers provided to agent."""
5160

5261
def model_post_init(self, __context: Any) -> None:
5362
super().model_post_init(None) # for sub_agents init

veadk/knowledgebase/backends/base_backend.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,21 @@
1818

1919

2020
class BaseKnowledgebaseBackend(ABC, BaseModel):
21+
"""Base backend for knowledgebase.
22+
23+
Attributes:
24+
index (str): Index or collection name of the vector storage.
25+
26+
Examples:
27+
You can implement your own knowledgebase backend.
28+
29+
```python
30+
class CustomKnowledgebaseBackend(BaseKnowledgebaseBackend):
31+
pass
32+
```
33+
"""
34+
2135
index: str
22-
"""Index or collection name of the vector storage."""
2336

2437
@abstractmethod
2538
def precheck_index_naming(self) -> None:

veadk/knowledgebase/backends/in_memory_backend.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,19 @@
2424

2525

2626
class InMemoryKnowledgeBackend(BaseKnowledgebaseBackend):
27+
"""A in-memory implementation backend for knowledgebase.
28+
29+
In-memory backend stores embedded text in a vector storage from Llama-index.
30+
31+
Attributes:
32+
embedding_config (EmbeddingModelConfig):
33+
Embedding config for text embedding and search.
34+
Embedding config contains embedding model name and the corresponding dim.
35+
"""
36+
2737
embedding_config: NormalEmbeddingModelConfig | EmbeddingModelConfig = Field(
2838
default_factory=EmbeddingModelConfig
2939
)
30-
"""Embedding model configs"""
3140

3241
def model_post_init(self, __context: Any) -> None:
3342
self._embed_model = OpenAILikeEmbedding(

0 commit comments

Comments
 (0)