Portada » Agents: Extending LLM functionality with OpenAI
Agente Multiusos

Agents: Extending LLM functionality with OpenAI

Today, the use of intelligent agents is revolutionizing the interaction between humans and technology. These agents, powered by LLMs such as GPT-4, are capable of performing complex tasks autonomously and efficiently. OpenAI offers tools to develop and deploy these agents, commonly known as OpenAI Agents.

What are OpenAI Agents?

OpenAI Agents are intelligent systems designed to perform specific tasks without human intervention. These agents can perform anything from simple automated tasks to achieving complex goals through a combination of reasoning, planning and continuous learning.

Essential components for creating OpenAI Agents

OpenAI provides a set of tools to build robust and efficient agents:

  • Models: These provide the core intelligence of the agent. Models such as GPT-4o, GPT-4.5 and GPT-4o-mini have different levels of capacity and latency. GPT-4o is ideal for tasks that require a balance between performance and speed, while GPT-4.5 stands out for its ability to execute complex tasks and GPT-4o-mini offers low latency for fast responses.
  • Tools: They facilitate the agent’s interaction with the environment. The main ones include:
    • Function calls: They allow integrating the agent with developer-defined functions to execute specific tasks.
    • Web search: Provides access to real-time, up-to-date information from the Internet.
    • Search in archives: Allows semantic searches in internal documents of the organization to extract relevant information.
  • Memory and knowledge: Using vector stores and embeddings, agents can store information and retrieve it efficiently to continuously improve their performance and accuracy. This long-term memory enables more complex and contextual tasks.
  • Guardrails (Safeguards): These are essential to ensure that the agent behaves in a safe and predictable manner. OpenAI provides:
    • Moderation API: Helps filter unsafe or inappropriate content automatically.
    • Hierarchies of instructions: They allow clearly defining priorities and specific rules on how the agent should act when faced with different situations.
  • Orchestration: OpenAI offers the Agent SDK, real-time monitoring tools and continuous evaluation systems, which facilitate the deployment, monitoring and optimization of agents in production.

How to Start Building Your Agent with OpenAI

Here is a practical and simple example to start developing an OpenAI Agent.

Step 1: Installing the SDK

pip install openai-agents

Step 2: Create a Simple Agent

Here is a basic example for defining an agent that makes calls to custom functions:

from openai import OpenAI

client = OpenAI(api_key="tu_clave_api")

# Definir una función personalizada
def obtener_clima(ciudad):
    # Simulación de respuesta
    return f"El clima actual en {ciudad} es soleado."

# Registrar la función en el agente
agente = client.agents.create(
    model="gpt-4o",
    tools=[{"type": "function", "function": obtener_clima}]
)

# Ejecutar el agente
respuesta = agente.execute("¿Cuál es el clima en Madrid hoy?")
print(respuesta)

Step 3: Add memory using Vector Stores

To provide your agent with memory, you can use vector stores:

from openai.embeddings_utils import get_embedding, cosine_similarity

# Crear embeddings
texto1 = "Madrid es una ciudad de España"
texto2 = "Sevilla es una ciudad española"

embedding1 = get_embedding(texto1, engine="text-embedding-3-large")
embedding2 = get_embedding(texto2, engine="text-embedding-3-large")

similitud = cosine_similarity(embedding1, embedding2)
print(f"Similitud entre textos: {similitud}")

This approach allows the agent to remember relevant information and improve its responses through semantic comparisons.

Step 4: Deploy and Monitor your Agent

Use the SDK to easily deploy and monitor your agents:

from openai.agents import Agent

agente = Agent.deploy(
    model="gpt-4o",
    tools=["web_search"],
    guardrails=["moderation"]
)

resultado = agente.execute("Encuentra las últimas noticias sobre inteligencia artificial.")
print(resultado)

# Monitorizar rendimiento
agente.monitor()

Conclusion

OpenAI Agents offer enormous potential to extend the capabilities of LLMs in a variety of scenarios, enabling more intelligent and autonomous interactions. With the tools provided by OpenAI, creating these agents is easier than ever. Ignos has the knowledge to assist you in the implementation of these types of solutions, simplifying the process of adopting these technologies and ensuring the return on investment.

This post is also available in: English Español

Artículos relacionados

Leave a Reply

Your email address will not be published. Required fields are marked *