Skip to main content

llama-index agent azure integration

Project description

LlamaIndex Azure Foundry Agent Integration

This package provides an Azure Foundry Agent integration for LlamaIndex. It allows you to leverage Azure AI Agent Service capabilities within your LlamaIndex applications. The provided AzureFoundryAgent inherits BaseWorkflowAgent from LlamaIndex, making it compatible with workflow-based multi-agent orchestration.

About Azure AI Agent Service

Azure AI Agent Service is a fully managed service designed to empower developers to securely build, deploy, and scale high-quality, and extensible AI agents without needing to manage the underlying compute and storage resources.

Installation

You can install the package via pip:

pip install llama-index-agent-azure

or if working from source:

cd llama_index/llama-index-integrations/agent/llama-index-agent-azure
pip install -e .

You may also want to install python-dotenv if you plan to use a .env file for environment variables:

pip install python-dotenv

Prerequisites

Before using this integration, ensure you have:

  1. An Azure account and a provisioned Azure OpenAI service or an Azure AI Project with an agent-compatible endpoint.
  2. The necessary environment variables set up for authentication. Typically, this involves:
    • AZURE_PROJECT_ENDPOINT: Your Azure AI Project endpoint.
    • Standard Azure authentication environment variables recognized by DefaultAzureCredential (e.g., AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET, or ensure you are logged in via Azure CLI).

Usage

Here's a basic example of how to use the AzureFoundryAgent with a function tool for function calling.

from llama_index.agent.azure_foundry_agent import AzureFoundryAgent
from dotenv import load_dotenv
import os

load_dotenv()

# Configure your Azure project endpoint
azure_project_endpoint = os.environ.get("AZURE_PROJECT_ENDPOINT")

if not azure_project_endpoint:
    raise ValueError("AZURE_PROJECT_ENDPOINT environment variable not set.")


# Define a sample tool (optional)
def get_weather(location: str) -> str:
    """Get the weather for a given location."""
    # This is a placeholder function. Replace with actual weather API call.
    return f"The weather in {location} is sunny."


# Instantiate the agent
# Note: The `model` parameter refers to a model deployment that should already be created in your Azure AI Project.
agent = AzureFoundryAgent(
    endpoint=azure_project_endpoint,
    model="gpt-4o",  # Specify your deployed model name
    name="my-azure-agent",
    instructions="You are a helpful assistant that can provide information and use tools.",
    verbose=True,
    tools=[get_weather],  # Pass your defined tools as a list
    run_retrieve_sleep_time=2,  # Time in seconds to wait between polling run status
)

# Run the agent
response = await agent.run(
    "What is the capital of France and what is the weather there?"
)
print("Agent Response:", response)

Example of using multimodal input with the agent:

# Example: Multimodal input (text + image)
# This works with multimodal-capable models such as gpt-4o
from llama_index.core.llms import ChatMessage, TextBlock, ImageBlock

multimodal_msg = ChatMessage(
    role="user",
    blocks=[
        TextBlock(text="Describe what you see in this image."),
        ImageBlock(url="https://example.com/sample-image.png"),
    ],
)
multimodal_response = await agent.run(multimodal_msg)
print("Multimodal Agent Response:", multimodal_response)


# Important: Azure agents and threads are stateful resources on Azure.
# Remember to clean them up from the Azure portal or using the Azure SDK
# await agent._client.agents.delete_agent(agent_id=agent._agent.id)
# await agent._client.agents.threads.delete(thread_id=agent._thread_id)

Key Parameters for AzureFoundryAgent

  • endpoint: The endpoint URL for your Azure AI Project or compatible service.
  • model: The identifier of the LLM model to be used by the agent (e.g., "gpt-4o", "gpt-35-turbo").
  • name: A name for your agent instance.
  • instructions: System instructions for the agent.
  • tools (Optional): A list of Python functions to be used as tools by the agent.
  • thread_id (Optional): An existing thread ID to continue a conversation. If not provided, a new thread is created.
  • verbose (Optional): Set to True for detailed logging.
  • run_retrieve_sleep_time (Optional): The time in seconds to wait between polling the status of an agent run. Defaults to 1.0.

Troubleshooting

  • Missing Environment Variables: Ensure AZURE_PROJECT_ENDPOINT and Azure credentials are set in your environment or .env file.
  • Resource Cleanup: Always delete agents and threads after use to avoid resource leaks and unnecessary Azure charges.
  • Dependency Issues: Make sure all required packages are installed, including python-dotenv if using .env files.

For more details, see the Azure AI Agent Service documentation.

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

llama_index_agent_azure_foundry-0.3.0.tar.gz (8.7 kB view details)

Uploaded Source

Built Distribution

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

File details

Details for the file llama_index_agent_azure_foundry-0.3.0.tar.gz.

File metadata

  • Download URL: llama_index_agent_azure_foundry-0.3.0.tar.gz
  • Upload date:
  • Size: 8.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for llama_index_agent_azure_foundry-0.3.0.tar.gz
Algorithm Hash digest
SHA256 cd7ae581a2d552df749fede3bdcdf7487e5efca52a84704af7b2b5b47b748a3f
MD5 91ff1b0f0948690b2da25dd02abdb374
BLAKE2b-256 6dd6f50596c5731d0ce8cfcdaeabdf1726ad80198d4ad27048c8e49ad2ae0acf

See more details on using hashes here.

File details

Details for the file llama_index_agent_azure_foundry-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: llama_index_agent_azure_foundry-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 7.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for llama_index_agent_azure_foundry-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e8a8044c98357a13432f01c5277ab90a020b03889b0fafc32313505d8ec94153
MD5 27d54357d4f18b1f5e3ddd6b93ca57df
BLAKE2b-256 8f5b17a29a80f7feda9b2afceeb41012d9eb7962bb4faf711378b7a999428475

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