This is my custom aioaiagent client
Project description
DM-aioaiagent
Urls
* Package contains both asynchronous
and synchronous
clients
Usage
Analogue to DMAioAIAgent
is the synchronous client DMAIAgent
.
Use agent with inner memory
By default, agent use inner memory to store the conversation history.
(You can set max count messages in memory by max_memory_messages
init argument)
import asyncio
from dm_aioaiagent import DMAioAIAgent
async def main():
# define a system message
system_message = "Your custom system message with role, backstory and goal"
# (optional) define a list of tools, if you want to use them
tools = [...]
# define a openai model, default is "gpt-4o-mini"
model_name = "gpt-4o"
# create an agent
ai_agent = DMAioAIAgent(system_message, tools, model=model_name)
# if you don't want to see the input and output messages from agent
# you can set `input_output_logging=False` init argument
# define the conversation message
input_messages = [
{"role": "user", "content": "Hello!"},
]
# call an agent
# specify `memory_id` argument to store the conversation history by your custom id
answer = await ai_agent.run(input_messages)
# define the next conversation message
input_messages = [
{"role": "user", "content": "I want to know the weather in Kyiv"}
]
# call an agent
answer = await ai_agent.run(input_messages)
# get full conversation history
conversation_history = ai_agent.get_memory_messages()
# clear conversation history
ai_agent.clear_memory()
if __name__ == "__main__":
asyncio.run(main())
Use agent without inner memory
If you want to control the memory of the agent, you can disable it by setting is_memory_enabled=False
import asyncio
from dm_aioaiagent import DMAioAIAgent
async def main():
# define a system message
system_message = "Your custom system message with role, backstory and goal"
# (optional) define a list of tools, if you want to use them
tools = [...]
# define a openai model, default is "gpt-4o-mini"
model_name = "gpt-4o"
# create an agent
ai_agent = DMAioAIAgent(system_message, tools, model=model_name,
is_memory_enabled=False)
# if you don't want to see the input and output messages from agent
# you can set input_output_logging=False
# define the conversation message
messages = [
{"role": "user", "content": "Hello!"}
]
# call an agent
new_messages = await ai_agent.run(messages)
# add new_messages to messages
messages.extend(new_messages)
# define the next conversation message
messages.append(
{"role": "user", "content": "I want to know the weather in Kyiv"}
)
# call an agent
new_messages = await ai_agent.run(messages)
if __name__ == "__main__":
asyncio.run(main())
Image vision
from dm_aioaiagent import DMAIAgent, ImageMessageContentBuilder
def main():
# create an agent
ai_agent = DMAIAgent(agent_name="image_vision", model="gpt-4o")
# create an image message content
# NOTE: text argument is optional
img_content = ImageMessageContentBuilder(image_url="https://your.domain/image",
text="Hello, what is shown in the photo?")
# define the conversation message
messages = [
{"role": "user", "content": "Hello!"},
{"role": "user", "content": img_content},
]
# call an agent
answer = ai_agent.run(messages)
if __name__ == "__main__":
main()
Set custom logger
If you want set up custom logger
from dm_aioaiagent import DMAioAIAgent
# create custom logger
class MyLogger:
def debug(self, message):
pass
def info(self, message):
pass
def warning(self, message):
print(message)
def error(self, message):
print(message)
# create an agent
ai_agent = DMAioAIAgent()
# set up custom logger for this agent
ai_agent.set_logger(MyLogger())
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
dm_aioaiagent-0.3.3.tar.gz
(6.8 kB
view details)
Built Distribution
File details
Details for the file dm_aioaiagent-0.3.3.tar.gz
.
File metadata
- Download URL: dm_aioaiagent-0.3.3.tar.gz
- Upload date:
- Size: 6.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0d4c1e0c16430a7cbc7e92a5c250bbc2d4d109bd955512387fd631b8881ede5d |
|
MD5 | 088f6e3f41901230fb07d68b45fbd945 |
|
BLAKE2b-256 | a214399d86a80e8cefb00a43b7215436d2110802bf9a7c74e0b6741c435a3ab7 |
File details
Details for the file dm_aioaiagent-0.3.3-py3-none-any.whl
.
File metadata
- Download URL: dm_aioaiagent-0.3.3-py3-none-any.whl
- Upload date:
- Size: 7.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5202497b4fba1e5a3ecdc5090576d3110bd880a04fd5a09dd2036a95dcde447d |
|
MD5 | b0129cf98a7057c2810f9972d97a25f9 |
|
BLAKE2b-256 | 14e64ab219f39db71ecda89571890112e1639f4dd62824dcf2a495f88909d558 |