AgentDev provides basic components that used on Bailian.platform with unified API
Project description
AgentDev
Overview
AgentDev is a component-based framework for building AI-powered applications. Key features include:
- Modular component architecture
- Integration with Dashscope services
- LangGraph compatibility
- Model Context Protocol (MCP) support
- Enterprise level tracing and metrics
- Extensible error handling system
Design Principles
- Components have single responsibility
- Low replacement cost with high reusability component
- Quick testing and deployment for individual components
- Clear dependency relationships through well-defined input/output parameters
- Compatibility with other open-source solutions
- Extensible base classes supporting logging and tracing
Key Components
- Bailian Search component: Enterprise level web search based on bailian official search ability.
- Bailian RAG component: Enterprise level RAG which retrieve relevant information from Bailian maintain by user.
- Bailian Intention component: Enterprise level Intention Center which classify user's intention with different label.
- Aliyun Tracing component: Enterprise level tracing that manage user tracing data by aliyun
- OpenAI and Bailian compatible LLM message schemas
- OpenAI compatible LLM component
- FastAPI server for SSE protoc
- Other key components as base capabilities to support Bailian Chat Services
Installation
pip install agentdev
Quick Start
Basic llm service
Create a python file named main.py with the following code.
Notice that the DashscopeChatRequest is the original Dashscope chat request format,
if you want to use openai compatible request, you can use OpenAIChatRequest or BailianChatRequest instead.
from agentdev.models.llm import BaseLLM
from agentdev.schemas.llm_schemas import DashscopeChatRequest
from agentdev.server.fastapi_server import FastApiServer
async def general_arun(request: DashscopeChatRequest):
"""Test arun method"""
llm = BaseLLM()
try:
async for chunk in await llm.arun(model=request.model, messages=request.input.messages,
parameters=request.parameters):
yield chunk
except Exception as e:
import traceback
print(f'error {e} with traceback {traceback.format_exc()}')
server = FastApiServer(
func=general_arun,
endpoint_path='/api/v1/chat/completions',
request_model=DashscopeChatRequest,
)
if __name__ == '__main__':
server.run()
Then run the python file with your DASHSCOPE_API_KEY
export DASHSCOPE_API_KEY=your_api_key
python main.py
then a local llm service will run on your local machine at http://127.0.0.1:8000/api/v1/chat/completions
query the service with curl
curl --location 'http://127.0.0.1:8000/api/v1/chat/completions' \
--header 'Content-Type: application/json' \
--data '{
"model": "qwen-max",
"input":{
"messages":[{"role": "user", "content":"今天天气如何"}]
},
"parameters": {
}
}'
the response should be like this
data:{"id":"chatcmpl-2b0cb0d9-82fa-9c2c-8364-c100111d84a3","choices":[{"delta":{"content":"","role":"assistant"},"index":0}],"created":1742953771,"model":"qwen-max","object":"chat.completion.chunk"}
data:{"id":"chatcmpl-2b0cb0d9-82fa-9c2c-8364-c100111d84a3","choices":[{"delta":{"content":"我"},"index":0}],"created":1742953771,"model":"qwen-max","object":"chat.completion.chunk"}
data:{"id":"chatcmpl-2b0cb0d9-82fa-9c2c-8364-c100111d84a3","choices":[{"delta":{"content":"目前"},"index":0}],"created":1742953771,"model":"qwen-max","object":"chat.completion.chunk"}
data:{"id":"chatcmpl-2b0cb0d9-82fa-9c2c-8364-c100111d84a3","choices":[{"delta":{"content":"无法直接获取实时天气"},"index":0}],"created":1742953771,"model":"qwen-max","object":"chat.completion.chunk"}
data:{"id":"chatcmpl-2b0cb0d9-82fa-9c2c-8364-c100111d84a3","choices":[{"delta":{"content":"信息。您可以通过查询网络"},"index":0}],"created":1742953771,"model":"qwen-max","object":"chat.completion.chunk"}
data:{"id":"chatcmpl-2b0cb0d9-82fa-9c2c-8364-c100111d84a3","choices":[{"delta":{"content":"、使用天气应用查看"},"index":0}],"created":1742953771,"model":"qwen-max","object":"chat.completion.chunk"}
data:{"id":"chatcmpl-2b0cb0d9-82fa-9c2c-8364-c100111d84a3","choices":[{"delta":{"content":",或者告诉我您"},"index":0}],"created":1742953771,"model":"qwen-max","object":"chat.completion.chunk"}
data:{"id":"chatcmpl-2b0cb0d9-82fa-9c2c-8364-c100111d84a3","choices":[{"delta":{"content":"所在的城市和地区,我可以提供"},"index":0}],"created":1742953771,"model":"qwen-max","object":"chat.completion.chunk"}
data:{"id":"chatcmpl-2b0cb0d9-82fa-9c2c-8364-c100111d84a3","choices":[{"delta":{"content":"一些一般性的天气信息和"},"index":0}],"created":1742953771,"model":"qwen-max","object":"chat.completion.chunk"}
data:{"id":"chatcmpl-2b0cb0d9-82fa-9c2c-8364-c100111d84a3","choices":[{"delta":{"content":"建议。如果需要准确"},"index":0}],"created":1742953771,"model":"qwen-max","object":"chat.completion.chunk"}
data:{"id":"chatcmpl-2b0cb0d9-82fa-9c2c-8364-c100111d84a3","choices":[{"delta":{"content":"的天气情况,请参考"},"index":0}],"created":1742953771,"model":"qwen-max","object":"chat.completion.chunk"}
data:{"id":"chatcmpl-2b0cb0d9-82fa-9c2c-8364-c100111d84a3","choices":[{"delta":{"content":"当地的气象预报。"},"index":0}],"created":1742953771,"model":"qwen-max","object":"chat.completion.chunk"}
data:{"id":"chatcmpl-2b0cb0d9-82fa-9c2c-8364-c100111d84a3","choices":[{"delta":{"content":""},"finish_reason":"stop","index":0}],"created":1742953771,"model":"qwen-max","object":"chat.completion.chunk"}
Basic component create
import asyncio
from agentdev.base.component import Component
from pydantic import BaseModel, Field
from typing import Any
# define the input format
class SearchInput(BaseModel):
"""
Search Input.
"""
query: str = Field(..., title='Query')
context: dict
# define the output format
class SearchOutput(BaseModel):
"""
Search Output.
"""
results: list[str]
context: dict
# define the component runtime method
class SearchComponent(Component[SearchInput, SearchOutput]):
"""
Search Component.
"""
async def arun(self, args: SearchInput, **kwargs: Any) -> SearchOutput:
"""
Run asynchronously.
"""
if not isinstance(args, SearchInput):
raise TypeError(
'Argument must be an instance of SearchInput or its subclass')
await asyncio.sleep(1) # 模拟异步操作
return SearchOutput(results=['result1', 'result2'],
context=args.context)
# instantiate the component
search_component = SearchComponent(
name='Search Component',
description='Search Component For Example',
config={})
search_input = SearchInput(query='query', context={})
# run
async def main():
search_output = await search_component.arun(search_input)
print(search_output)
print(search_component.function_schema)
asyncio.run(main())
Requirements
- Quick deployment similar to assistant serving
- Standardized output like Marvin
- Agent evaluation capabilities
Solutions Implemented
- Single-responsibility component interfaces with clear input/output definitions
- Extensible base classes with optional logging/tracing
- Mixins for integrating with open-source ecosystems
Development
Testing
Run tests using pytest:
pytest test/
Contributing
Please follow these guidelines:
- Write unit tests for new components
- Maintain consistent documentation
- Follow existing code style and patterns
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file agentdev-0.5.0.tar.gz.
File metadata
- Download URL: agentdev-0.5.0.tar.gz
- Upload date:
- Size: 87.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
54f3d9843a61285fc7c2e6de5ec4ddb0f4bd35e3a44849dd28bfdc17c159ceeb
|
|
| MD5 |
2c5e2af67be7ca682cadf48bc09fc709
|
|
| BLAKE2b-256 |
354b46a7f7d962bab18591c2f485f408418a4bc61e1879d1d7a44a4d34549989
|
File details
Details for the file agentdev-0.5.0-py3-none-any.whl.
File metadata
- Download URL: agentdev-0.5.0-py3-none-any.whl
- Upload date:
- Size: 110.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6f27b02a4eafbf93335e09977a4f9c54c38e37d97e037d7115f6c97aa42aa36d
|
|
| MD5 |
e8b2067442b44999afffc672b1159d04
|
|
| BLAKE2b-256 |
7b6f79927a883f0ef4851db06efcb502df964696e07365ed4a84461b5aade298
|