Skip to main content

This is my custom aioaiagent client

Project description

DM-aioaiagent

Urls

* Package contains both asynchronous and synchronous clients

Installation

By default, the package ships with OpenAI support. Other providers are optional extras:

pip install dm-aioaiagent                       # OpenAI only
pip install dm-aioaiagent[anthropic]            # + Anthropic
pip install dm-aioaiagent[anthropic,gemini]     # several at once
pip install dm-aioaiagent[all]                  # every supported provider

Available extras: anthropic, gemini, groq, mistral, deepseek, ollama, all.

If you call a model from a provider whose package is not installed, init_chat_model will raise an ImportError with the exact pip install command you need.

Providers

Provider resolution is delegated to LangChain's init_chat_model — the agent picks the provider automatically by model name prefix when possible. For everything else, use the "provider:model" mask.

# Auto-detected from model prefix (rules come from LangChain's init_chat_model)
agent = DMAioAIAgent(model="gpt-4o-mini")              # → openai
agent = DMAioAIAgent(model="claude-3-5-sonnet-latest") # → anthropic
agent = DMAioAIAgent(model="gemini-2.0-flash")         # → google_vertexai (see note below)

# Explicit provider via "provider:model" mask
agent = DMAioAIAgent(model="google_genai:gemini-2.0-flash")
agent = DMAioAIAgent(model="groq:llama-3.1-70b-versatile")
agent = DMAioAIAgent(model="mistralai:mistral-large-latest")
agent = DMAioAIAgent(model="deepseek:deepseek-chat")
agent = DMAioAIAgent(model="ollama:llama3.1")

# OpenAI-compatible gateway (OpenRouter, Together, vLLM, LiteLLM proxy, ...)
# Works without installing any extra — just point to the OpenAI-compatible URL.
agent = DMAioAIAgent(
    model="meta-llama/llama-3.1-70b-instruct",
    llm_provider_base_url="https://openrouter.ai/api/v1",
    llm_provider_api_key="sk-or-...",
)

Note about Gemini. LangChain's auto-detect maps the gemini* prefix to google_vertexai (Google Cloud Vertex AI, requires a GCP service account). If you have a regular Google AI Studio API key (GOOGLE_API_KEY), use the google_genai: mask explicitly:

agent = DMAioAIAgent(model="google_genai:gemini-2.0-flash")

Supported provider keys for the "provider:model" mask (list inherited from LangChain): openai, anthropic, azure_openai, azure_ai, google_vertexai, google_genai, bedrock, bedrock_converse, cohere, fireworks, together, mistralai, huggingface, groq, ollama, google_anthropic_vertex, deepseek, ibm, nvidia, xai, perplexity.

Note about parallel tool calls

parallel_tool_calls is currently mapped only for OpenAI and Anthropic (their APIs use different formats). For other providers the parameter is silently ignored — extend per-provider mapping if you need it.

Usage

Analogue to DMAioAIAgent is the synchronous client DMAIAgent.

Windows Setup

import asyncio
import sys

if sys.platform == "win32":
    asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())

Api Key Setup

Each provider reads its API key from a dedicated environment variable, e.g. OPENAI_API_KEY, ANTHROPIC_API_KEY, GOOGLE_API_KEY, GROQ_API_KEY, MISTRAL_API_KEY, etc. Alternatively, pass the key explicitly via the llm_provider_api_key argument — useful for multi-tenant setups, custom gateways, or runtime key rotation.

Use load_dotenv to load the .env file.

from dotenv import load_dotenv
load_dotenv()

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)

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

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

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()

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.6.0.tar.gz (11.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.6.0-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: dm_aioaiagent-0.6.0.tar.gz
  • Upload date:
  • Size: 11.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for dm_aioaiagent-0.6.0.tar.gz
Algorithm Hash digest
SHA256 84140e2fe1234791bafc5a186cc2b9a5e917e94e1e2f9ebf11a955dd8e82b4f0
MD5 27de3197e8080cfb5e1fb0965798639e
BLAKE2b-256 bc455cb20e4f8259c680ef4f2ba4601e9aac87dec05a4e99fd0f1b187d3efea9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: dm_aioaiagent-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 10.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for dm_aioaiagent-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 222ce3337cf70a552d98da550a4b3b31c0c754fba009b53923a1f7824bc65e3a
MD5 3afddcabbc67bd95e9378c7922e8078f
BLAKE2b-256 e4a8bb66e96e86d885214ed8feff9977654a9c5e9c50483efdd8e0aabebf4444

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