from haystack.components.agents import Agent
from haystack.components.generators.chat import OpenAIChatGenerator
from haystack.dataclasses import ChatMessage
from haystack.utils import Secret
# Securely load your API key
requesty_api_key = Secret.from_env_var("REQUESTY_API_KEY"),
# Initialize the agent with Requesty router
agent = Agent(
chat_generator=OpenAIChatGenerator(
model="xai/grok-4",
api_key=requesty_api_key,
api_base_url="https://router.requesty.ai/v1",
),
system_prompt="You are a helpful web agent powered by Requesty router.",
)
# Define the question
question = "What are the benefits of using Requesty router with Haystack?"
# Run the agent and get the response
result = agent.run(messages=[ChatMessage.from_user(question)])
# Print the response
print(result['last_message'].text)