Skip to content

Commit bd98ebe

Browse files
Docs: Add all docs.
1 parent 9cd0906 commit bd98ebe

File tree

25 files changed

+1203
-2254
lines changed

25 files changed

+1203
-2254
lines changed

demo/basic.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ async def basic_example():
2525
# FunctionConfig defines general behavior of the agent
2626
func = FunctionConfig(
2727
use_minimal_context=False, # Use full context or minimal context
28-
tool_calling_mode="agent", # How tools are called
29-
agent_thought_mode="reasoning", # How agent thinks through problems
3028
)
3129

3230
# LLMConfig defines language model behavior

demo/basic_with_sessions.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ async def basic_with_sessions_example():
2828
# Configure AmritaCore with security features
2929
func = FunctionConfig(
3030
use_minimal_context=False,
31-
tool_calling_mode="agent",
32-
agent_thought_mode="reasoning",
3331
)
3432

3533
llm = LLMConfig(

demo/cli.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,6 @@ async def main():
104104
# Set configuration
105105
func = FunctionConfig(
106106
use_minimal_context=False,
107-
tool_calling_mode="agent",
108-
agent_thought_mode="reasoning",
109107
# agent_mcp_client_enable=True,
110108
# agent_mcp_server_scripts=[],
111109
)

demo/stream_using.py

Lines changed: 12 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,98 +1,24 @@
1-
"""
2-
Basic Example for AmritaCore - A simple demonstration of core functionality.
3-
4-
This example demonstrates the streaming response usage of AmritaCore.
5-
"""
6-
71
import asyncio
82

9-
from amrita_core import ChatObject, init, load_amrita
10-
from amrita_core.chatmanager import RESPONSE_TYPE
11-
from amrita_core.config import AmritaConfig
12-
from amrita_core.types import MemoryModel, Message
3+
from amrita_core import create_agent
134

145

156
async def minimal_example():
16-
"""
17-
A minimal example showing the essential steps to run AmritaCore with stream response.
18-
"""
19-
print("\n🧪 Minimal Example")
20-
print("-" * 30)
21-
22-
# Minimal configuration
23-
from amrita_core.config import set_config
24-
25-
set_config(AmritaConfig())
26-
27-
# Load AmritaCore
28-
await load_amrita()
29-
30-
# Note: In a real scenario, you would configure your model preset here
31-
print("✅ AmritaCore loaded with minimal configuration")
32-
33-
# Create context and system message
34-
context = MemoryModel()
35-
train = Message(content="You are a helpful assistant.", role="system")
36-
37-
# Create and run a chat interaction
38-
chat = ChatObject(
39-
context=context,
40-
session_id="minimal_session",
41-
user_input="What can you do?",
42-
train=train.model_dump(),
7+
# Create an agent with minimal parameters
8+
agent = create_agent(
9+
url="YOUR_API_ENDPOINT", # Replace with your API endpoint
10+
key="YOUR_API_KEY", # Replace with your API key
11+
model_config={"model": "gpt-3.5-turbo", "stream": True},
4312
)
44-
# Collect response (just to show it works)
45-
i = 0
46-
async with chat.begin():
47-
async for chunk in chat.get_response_generator():
48-
print(
49-
chunk.get_content() if not isinstance(chunk, str) else chunk,
50-
end="",
51-
flush=True,
52-
)
53-
i += 1
54-
print(f"💬 Response length: {i} characters")
55-
print("✅ Minimal example completed!")
56-
57-
58-
async def minimal_example_with_callback():
59-
"""
60-
A minimal example showing the essential steps to run AmritaCore with stream response and with callback's using.
61-
"""
62-
length: int = 0
63-
64-
async def callback(message: RESPONSE_TYPE):
65-
nonlocal length
66-
print(message, end="")
67-
length += len(str(message))
6813

69-
print("\n🧪With callback")
70-
print("-" * 30)
71-
from amrita_core.config import set_config
14+
# Get a chat object for the interaction
15+
chat = agent.get_chatobject("Hello, what can you do?")
7216

73-
set_config(AmritaConfig())
74-
await load_amrita()
75-
# Create context and system message
76-
context = MemoryModel()
77-
train = Message(content="You are a helpful assistant.", role="system")
78-
79-
chat = ChatObject(
80-
context=context,
81-
session_id="minimal_session",
82-
user_input="What can you do?",
83-
train=train.model_dump(),
84-
callback=callback, # Pass callback to ChatObject
85-
)
86-
# You can also use `chat.set_callback_func(callback)` to do it!
87-
# Collect response (just to show it works)
88-
await chat.begin()
89-
print(f"💬 Response length: {length} characters")
90-
print("✅ Example completed!")
17+
# Execute the interaction and get the response
18+
async with chat.begin():
19+
print(await chat.full_response())
9120

9221

22+
# Run the example
9323
if __name__ == "__main__":
94-
# Initialize AmritaCore
95-
init()
9624
asyncio.run(minimal_example())
97-
98-
print("\n✨ All examples completed!")

docs/.vitepress/config.mts

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ export default withMermaid({
6666
{ text: "Event System", link: "/guide/concepts/event" },
6767
{ text: "Tool System", link: "/guide/concepts/tool" },
6868
{ text: "Data Management", link: "/guide/concepts/management" },
69+
{ text: "Agent Strategy", link: "/guide/concepts/agent-strategy" },
6970
],
7071
},
7172
{
@@ -107,6 +108,18 @@ export default withMermaid({
107108
text: "AmritaConfig",
108109
link: "/guide/api-reference/classes/AmritaConfig",
109110
},
111+
{
112+
text: "AgentRuntime",
113+
link: "/guide/api-reference/classes/AgentRuntime",
114+
},
115+
{
116+
text: "AgentStrategy",
117+
link: "/guide/api-reference/classes/AgentStrategy",
118+
},
119+
{
120+
text: "AmritaAgentStrategy",
121+
link: "/guide/api-reference/classes/AmritaAgentStrategy",
122+
},
110123
{
111124
text: "BaseModel",
112125
link: "/guide/api-reference/classes/BaseModel",
@@ -151,6 +164,10 @@ export default withMermaid({
151164
text: "ModelPreset",
152165
link: "/guide/api-reference/classes/ModelPreset",
153166
},
167+
{
168+
text: "StrategyContext",
169+
link: "/guide/api-reference/classes/StrategyContext",
170+
},
154171
{
155172
text: "TextContent",
156173
link: "/guide/api-reference/classes/TextContent",
@@ -263,6 +280,7 @@ export default withMermaid({
263280
{ text: "事件系统", link: "/zh/guide/concepts/event" },
264281
{ text: "工具系统", link: "/zh/guide/concepts/tool" },
265282
{ text: "数据管理", link: "/zh/guide/concepts/management" },
283+
{ text: "Agent 策略", link: "/zh/guide/concepts/agent-strategy" },
266284
],
267285
},
268286
{
@@ -301,6 +319,18 @@ export default withMermaid({
301319
text: "AmritaConfig",
302320
link: "/zh/guide/api-reference/classes/AmritaConfig",
303321
},
322+
{
323+
text: "AgentRuntime",
324+
link: "/zh/guide/api-reference/classes/AgentRuntime",
325+
},
326+
{
327+
text: "AgentStrategy",
328+
link: "/zh/guide/api-reference/classes/AgentStrategy",
329+
},
330+
{
331+
text: "AmritaAgentStrategy",
332+
link: "/zh/guide/api-reference/classes/AmritaAgentStrategy",
333+
},
304334
{
305335
text: "BaseModel",
306336
link: "/zh/guide/api-reference/classes/BaseModel",
@@ -317,6 +347,10 @@ export default withMermaid({
317347
text: "DependsFactory",
318348
link: "/zh/guide/api-reference/classes/DependsFactory",
319349
},
350+
{
351+
text: "FallbackContext",
352+
link: "/zh/guide/api-reference/classes/FallbackContext",
353+
},
320354
{
321355
text: "Function",
322356
link: "/zh/guide/api-reference/classes/Function",
@@ -325,10 +359,6 @@ export default withMermaid({
325359
text: "FunctionDefinitionSchema",
326360
link: "/zh/guide/api-reference/classes/FunctionDefinitionSchema",
327361
},
328-
{
329-
text: "FallbackContext",
330-
link: "/zh/guide/api-reference/classes/FallbackContext",
331-
},
332362
{
333363
text: "MemoryModel",
334364
link: "/zh/guide/api-reference/classes/MemoryModel",
@@ -345,6 +375,10 @@ export default withMermaid({
345375
text: "ModelPreset",
346376
link: "/zh/guide/api-reference/classes/ModelPreset",
347377
},
378+
{
379+
text: "StrategyContext",
380+
link: "/zh/guide/api-reference/classes/StrategyContext",
381+
},
348382
{
349383
text: "TextContent",
350384
link: "/zh/guide/api-reference/classes/TextContent",
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# AgentRuntime
2+
3+
The AgentRuntime class is a high-level wrapper around ChatObject that provides a reusable agent operation interface.
4+
5+
This class encapsulates the complexity of ChatObject and provides a simplified API for agent interactions. It maintains session state, configuration, and strategy settings, making it a reusable object for multiple agent operations within the same context.
6+
7+
## Properties
8+
9+
- `strategy` (type[AgentStrategy]): Agent strategy class used for execution
10+
- `session_id` (str): Session ID for the agent
11+
- `session` (SessionData | None): Session data or None if no session
12+
- `preset` (ModelPreset): Model preset configuration
13+
- `config` (AmritaConfig): Amrita configuration object
14+
- `train` (Message[str]): Training data (system prompts)
15+
- `context` (MemoryModel): Memory context for the conversation
16+
- `template` (Template): Jinja2 template used to render system role message
17+
18+
## Constructor Parameters
19+
20+
- `config` ([AmritaConfig](AmritaConfig.md)): Amrita configuration object containing global configuration settings
21+
- `preset` ([ModelPreset](ModelPreset.md)): Model preset configuration defining basic model parameters and settings
22+
- `strategy` (type[AgentStrategy], optional): Agent strategy class, defaults to AmritaAgentStrategy
23+
- `template` (Template | str, optional): Train template to render system role message, defaults to DEFAULT_TEMPLATE
24+
- `session` (SessionData | str | None, optional): Session data or session ID string for restoring existing sessions. If None, a new session will be created
25+
- `train` (dict[str, str] | Message[str] | None, optional): Training data (system prompts), can be in dictionary format or as a Message object
26+
- `no_session` (bool, optional): Whether to disable session functionality. If True, session management will be disabled but a temporary session ID will still be assigned
27+
28+
## Methods
29+
30+
### set_strategy(strategy)
31+
32+
Set the agent strategy to be used for execution.
33+
34+
**Parameters**:
35+
36+
- `strategy` (type[AgentStrategy]): The agent strategy to be used for execution
37+
38+
### get_chatobject(input, \*\*kwargs)
39+
40+
Get a chat object for a specific interaction.
41+
42+
**Parameters**:
43+
44+
- `input` (USER_INPUT): Input from the user
45+
- `**kwargs`: Additional keyword arguments passed to ChatObject constructor
46+
47+
**Returns**: [ChatObject](ChatObject.md) - A configured ChatObject instance ready for execution
48+
49+
## Usage Example
50+
51+
```python
52+
from amrita_core import create_agent
53+
54+
# Create an agent using the factory function
55+
agent = create_agent(
56+
url="https://api.example.com",
57+
key="your-api-key",
58+
model_config={"model": "gpt-4", "temperature": 0.7}
59+
)
60+
61+
# Get a chat object for interaction
62+
chat = agent.get_chatobject("Hello, what can you do?")
63+
64+
# Execute the interaction
65+
async with chat.begin():
66+
response = await chat.full_response()
67+
print(response)
68+
```
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# AgentStrategy
2+
3+
The AgentStrategy abstract base class defines how an agent should execute its workflow.
4+
5+
This class provides a unified interface for different types of agent execution strategies, allowing the system to support various agent patterns (basic tool calling, RAG, complex workflows).
6+
7+
## Strategy Categories
8+
9+
Different strategy categories have different execution patterns:
10+
11+
- **'agent'**: Uses `single_execute()` method for step-by-step tool calling, managed by the framework
12+
- **'rag'**: Uses `run()` method with minimal context (only system message and user query)
13+
- **'workflow'**: Uses `run()` method with full manual control over tool calling and context management
14+
- **'agent-mixed'**: Uses `single_execute()` method but can handle both RAG and Agent modes dynamically
15+
16+
## Properties
17+
18+
- `session` (SessionData | None): The session data associated with the current chat session, or None if not available
19+
- `tools_manager` (MultiToolsManager): Manager for handling available tools in the current context
20+
- `chat_object` (ChatObject): The chat object for yielding responses and managing the conversation flow
21+
- `ctx` (StrategyContext): The strategy context containing execution parameters and configuration
22+
23+
## Constructor Parameters
24+
25+
- `ctx` ([StrategyContext](StrategyContext.md)): Strategy context containing chat_object, configuration, and message context
26+
27+
## Abstract Methods
28+
29+
### get_category()
30+
31+
Get the category of the agent strategy.
32+
33+
**Returns**: Literal["agent", "workflow", "rag", "agent-mixed"] - The strategy category as a literal string indicating execution pattern.
34+
35+
## Methods
36+
37+
### single_execute()
38+
39+
Execute a single agent step for 'agent' and 'agent-mixed' category strategies.
40+
41+
This method is called by the framework to perform one iteration of tool calling. The framework handles the loop management, call counting, and termination conditions.
42+
43+
**Returns**: bool - True if should continue to next execution, False to stop.
44+
45+
**Note**: This method is used by 'agent' and 'agent-mixed' category strategies. 'rag' and 'workflow' category strategies should implement `run()` instead.
46+
47+
### run()
48+
49+
Run the complete agent strategy for 'rag' and 'workflow' category strategies.
50+
51+
This method gives full control to the strategy implementation for managing tool calling iterations, context construction, error handling, and response generation.
52+
53+
**Note**: This method is used by 'rag' and 'workflow' category strategies. 'agent' and 'agent-mixed' category strategies should implement `single_execute()` instead.
54+
55+
### on_limited()
56+
57+
Handle the event when the agent reaches its tool calling limit.
58+
59+
This method is called when the agent strategy has reached the maximum allowed number of tool calls as configured by the framework.
60+
61+
### on_exception(exc)
62+
63+
Handle exceptions that occur during strategy execution.
64+
65+
**Parameters**:
66+
- `exc` (BaseException): The exception that occurred during execution

0 commit comments

Comments
 (0)