# DM-aioaiagent
## Urls
* [PyPI](https://pypi.org/project/dm-aioaiagent)
* [GitHub](https://github.com/MykhLibs/dm-aioaiagent)
### * Package contains both `asynchronous` and `synchronous` clients
## Usage
Analogue to `DMAioAIAgent` is the synchronous client `DMAIAgent`.
### Use agent *with* inner memory and run *single* message
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)
```python
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
# call an agent
answer = await ai_agent.run("Hello!")
# call an agent
answer = await ai_agent.run("I want to know the weather in Kyiv")
# get full conversation history
conversation_history = ai_agent.memory_messages
# clear conversation history
ai_agent.clear_memory_messages()
if __name__ == "__main__":
asyncio.run(main())
```
### Use agent *without* inner memory and run *multiple* messages
If you want to control the memory of the agent, you can disable it by setting `is_memory_enabled=False`
```python
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(s)
messages = [
{"role": "user", "content": "Hello!"}
]
# call an agent
new_messages = await ai_agent.run_messages(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(messages)
if __name__ == "__main__":
asyncio.run(main())
```
### Image vision
```python
from dm_aioaiagent import DMAIAgent, OpenAIImageMessageContent
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 = OpenAIImageMessageContent(image_url="https://your.domain/image",
text="Hello, what is shown in the photo?")
# define the conversation messages
messages = [
{"role": "user", "content": "Hello!"},
{"role": "user", "content": img_content},
]
# call an agent
new_messages = ai_agent.run_messages(messages)
answer = new_messages[-1].content
if __name__ == "__main__":
main()
```
### Set custom logger
_If you want set up custom logger_
```python
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())
```
Raw data
{
"_id": null,
"home_page": "https://pypi.org/project/dm-aioaiagent",
"name": "dm-aioaiagent",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": "dm aioaiagent",
"author": "dimka4621",
"author_email": "mismartconfig@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/5e/61/722f6e825b66e8c18e7b5b78b750aa78a9f0d06683b22498919757420e32/dm_aioaiagent-0.4.5.tar.gz",
"platform": null,
"description": "# DM-aioaiagent\n\n## Urls\n\n* [PyPI](https://pypi.org/project/dm-aioaiagent)\n* [GitHub](https://github.com/MykhLibs/dm-aioaiagent)\n\n### * Package contains both `asynchronous` and `synchronous` clients\n\n## Usage\n\nAnalogue to `DMAioAIAgent` is the synchronous client `DMAIAgent`.\n\n### Use agent *with* inner memory and run *single* message\n\nBy default, agent use inner memory to store the conversation history.\n\n(You can set *max count messages in memory* by `max_memory_messages` init argument)\n\n```python\nimport asyncio\nfrom dm_aioaiagent import DMAioAIAgent\n\n\nasync def main():\n # define a system message\n system_message = \"Your custom system message with role, backstory and goal\"\n\n # (optional) define a list of tools, if you want to use them\n tools = [...]\n\n # define a openai model, default is \"gpt-4o-mini\"\n model_name = \"gpt-4o\"\n\n # create an agent\n ai_agent = DMAioAIAgent(system_message, tools, model=model_name)\n # if you don't want to see the input and output messages from agent\n # you can set `input_output_logging=False` init argument\n\n # call an agent\n answer = await ai_agent.run(\"Hello!\")\n\n # call an agent\n answer = await ai_agent.run(\"I want to know the weather in Kyiv\")\n\n # get full conversation history\n conversation_history = ai_agent.memory_messages\n\n # clear conversation history\n ai_agent.clear_memory_messages()\n\n\nif __name__ == \"__main__\":\n asyncio.run(main())\n```\n\n### Use agent *without* inner memory and run *multiple* messages\n\nIf you want to control the memory of the agent, you can disable it by setting `is_memory_enabled=False`\n\n```python\nimport asyncio\nfrom dm_aioaiagent import DMAioAIAgent\n\n\nasync def main():\n # define a system message\n system_message = \"Your custom system message with role, backstory and goal\"\n\n # (optional) define a list of tools, if you want to use them\n tools = [...]\n\n # define a openai model, default is \"gpt-4o-mini\"\n model_name = \"gpt-4o\"\n\n # create an agent\n ai_agent = DMAioAIAgent(system_message, tools, model=model_name,\n is_memory_enabled=False)\n # if you don't want to see the input and output messages from agent\n # you can set input_output_logging=False\n\n # define the conversation message(s)\n messages = [\n {\"role\": \"user\", \"content\": \"Hello!\"}\n ]\n\n # call an agent\n new_messages = await ai_agent.run_messages(messages)\n\n # add new_messages to messages\n messages.extend(new_messages)\n\n # define the next conversation message\n messages.append(\n {\"role\": \"user\", \"content\": \"I want to know the weather in Kyiv\"}\n )\n\n # call an agent\n new_messages = await ai_agent.run_messages(messages)\n\n\nif __name__ == \"__main__\":\n asyncio.run(main())\n```\n\n### Image vision\n\n```python\nfrom dm_aioaiagent import DMAIAgent, OpenAIImageMessageContent\n\n\ndef main():\n # create an agent\n ai_agent = DMAIAgent(agent_name=\"image_vision\", model=\"gpt-4o\")\n\n # create an image message content\n # NOTE: text argument is optional\n img_content = OpenAIImageMessageContent(image_url=\"https://your.domain/image\",\n text=\"Hello, what is shown in the photo?\")\n\n # define the conversation messages\n messages = [\n {\"role\": \"user\", \"content\": \"Hello!\"},\n {\"role\": \"user\", \"content\": img_content},\n ]\n\n # call an agent\n new_messages = ai_agent.run_messages(messages)\n answer = new_messages[-1].content\n\n\nif __name__ == \"__main__\":\n main()\n```\n\n### Set custom logger\n\n_If you want set up custom logger_\n\n```python\nfrom dm_aioaiagent import DMAioAIAgent\n\n\n# create custom logger\nclass MyLogger:\n def debug(self, message):\n pass\n\n def info(self, message):\n pass\n\n def warning(self, message):\n print(message)\n\n def error(self, message):\n print(message)\n\n\n# create an agent\nai_agent = DMAioAIAgent()\n\n# set up custom logger for this agent\nai_agent.set_logger(MyLogger())\n```\n",
"bugtrack_url": null,
"license": null,
"summary": "This is my custom aioaiagent client",
"version": "0.4.5",
"project_urls": {
"GitHub": "https://github.com/MykhLibs/dm-aioaiagent",
"Homepage": "https://pypi.org/project/dm-aioaiagent"
},
"split_keywords": [
"dm",
"aioaiagent"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "fda0cccb1e5bf0b14819f0ac83407142c2fdc7325e9431501353f7036aa9dfe2",
"md5": "d32465a3450ee91ef90b204883eaeb62",
"sha256": "245b4d92daadb4ecfba49bd4ef35258ae4b2c7853cc21de7ad12c0f5fef73e25"
},
"downloads": -1,
"filename": "dm_aioaiagent-0.4.5-py3-none-any.whl",
"has_sig": false,
"md5_digest": "d32465a3450ee91ef90b204883eaeb62",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 7988,
"upload_time": "2025-02-01T11:47:54",
"upload_time_iso_8601": "2025-02-01T11:47:54.759169Z",
"url": "https://files.pythonhosted.org/packages/fd/a0/cccb1e5bf0b14819f0ac83407142c2fdc7325e9431501353f7036aa9dfe2/dm_aioaiagent-0.4.5-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "5e61722f6e825b66e8c18e7b5b78b750aa78a9f0d06683b22498919757420e32",
"md5": "d99764f02e73bed3c0179e68ea856a53",
"sha256": "5688ddc4c0996beae8db5e1572c313e7fad226636617a8b2c705ff50b1e0a6b3"
},
"downloads": -1,
"filename": "dm_aioaiagent-0.4.5.tar.gz",
"has_sig": false,
"md5_digest": "d99764f02e73bed3c0179e68ea856a53",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 7631,
"upload_time": "2025-02-01T11:47:56",
"upload_time_iso_8601": "2025-02-01T11:47:56.283435Z",
"url": "https://files.pythonhosted.org/packages/5e/61/722f6e825b66e8c18e7b5b78b750aa78a9f0d06683b22498919757420e32/dm_aioaiagent-0.4.5.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-02-01 11:47:56",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "MykhLibs",
"github_project": "dm-aioaiagent",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [
{
"name": "dm-logger",
"specs": [
[
"~=",
"0.5.2"
]
]
},
{
"name": "python-dotenv",
"specs": [
[
">=",
"1.0.0"
]
]
},
{
"name": "pydantic",
"specs": [
[
">=",
"2.9.2"
],
[
"<",
"3.0.0"
]
]
},
{
"name": "langchain",
"specs": [
[
"~=",
"0.3.0"
]
]
},
{
"name": "langchain-core",
"specs": [
[
"~=",
"0.3.5"
]
]
},
{
"name": "langchain-community",
"specs": [
[
"~=",
"0.3.0"
]
]
},
{
"name": "langchain-openai",
"specs": [
[
"~=",
"0.3.0"
]
]
},
{
"name": "langchain-anthropic",
"specs": [
[
"~=",
"0.3.0"
]
]
},
{
"name": "langgraph",
"specs": [
[
"~=",
"0.2.23"
]
]
},
{
"name": "langsmith",
"specs": [
[
"~=",
"0.1.144"
]
]
},
{
"name": "grandalf",
"specs": [
[
">=",
"0.8"
]
]
}
],
"lcname": "dm-aioaiagent"
}