Skip to main content

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, 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 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


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.6.tar.gz (7.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dm_aioaiagent-0.3.6-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file dm_aioaiagent-0.3.6.tar.gz.

File metadata

  • Download URL: dm_aioaiagent-0.3.6.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for dm_aioaiagent-0.3.6.tar.gz
Algorithm Hash digest
SHA256 cf893eef480f0aae5fb2182bbaae1ce1ddf1057ebc535c8874db136287999a85
MD5 6e56d0d55f20e9c59cca2ec79edff388
BLAKE2b-256 fd3020363a9f2ae7b6ec7ebe736117a0bb48bd3d7e0d49e8ec8bbd93df67c0bf

See more details on using hashes here.

File details

Details for the file dm_aioaiagent-0.3.6-py3-none-any.whl.

File metadata

  • Download URL: dm_aioaiagent-0.3.6-py3-none-any.whl
  • Upload date:
  • Size: 7.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for dm_aioaiagent-0.3.6-py3-none-any.whl
Algorithm Hash digest
SHA256 e5de72ca5afc9d863682efc232f2f4ad4b35e78947ac2b4a84bd92a76a58805d
MD5 cfcbf8c423fd3353e5d154ff8d832fd7
BLAKE2b-256 e71a969f416cfc70473e20f26b24d064022a3006ab8e493e4c7577da7eef19d1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page