What is Agents API?
The Orq.ai Agents API is a powerful framework within the Orq.ai ecosystem that enables developers to build intelligent, autonomous AI agents capable of reasoning, using tools, maintaining context, and collaborating with other agents. It sits at the core of Orq.ai’s agentic architecture, working seamlessly with other platform components:- Deployments: Version-controlled configurations for your AI applications
- Gateway: Unified entry point for routing requests and managing LLM providers
- Agents: Autonomous entities that execute tasks using reasoning, tools, and context
Common Problems Agents Solve
- Complex Task Orchestration: Traditional chatbots struggle with multi-step workflows. Agents can break down complex requests into subtasks and use an orchestrator to delegate them between sub-agents that communicate via the A2A Protocol.
- Persistent Memory & Personalization Unlike stateless API calls, Agents maintain conversation history and user preferences across sessions through Memory Stores, enabling truly personalized employee experiences.
- Grounding & Accuracy By integrating Knowledge Bases, Agents ground their responses in your company’s actual policies and documents, reducing hallucinations
What we are going to build?
You will build an HR management system using Orq.ai Agents, where employees can get instant answers to HR questions, submit requests, and receive personalized support. You can follow along the steps in the Google Colab notebook. The system will include specialized agents for different HR domains (benefits questions, PTO calculation) orchestrated by a coordinator agent that intelligently routes requests. You’ll learn to implement persistent memory for personalized interactions and knowledge base integration for policy-compliant answers.Prerequisites
- Python 3.8+ python or higher
- An API Key ready to be used with the API.
-
Orq.ai SDK installed
-
A workspace with a Project named
agentsand Folder. -
Copy the
pathproperty ( You will use it in code aspath="agent")
1
Defining an Agent
Agents are defined via JSON payloads or the Python SDK. Key elements include Metadata - to set the tone of the agent and Configuration parameters to fine tune the agentAgent MetadataExpected output:Next, you need to invoke a response from a newly created agent:Expected outputAfter receiving a task response, you can continue the conversation by sending additional messages to the same agent. To enable multi-turn interactions where the agent maintains context from previous exchanges reference in the next run your previous task using Expected output:
role: description and instructionsdescription: short description of agent’s purposeinstructions: instructions for the agent behaviour
model: choose from providers e.g.openai/gpt-4o,anthropic/claude-3-5-sonnetand set the number ofretrieson specific error codessettings: Configuration settings for the agent’s behavior, such as:max_iterations: Maximum iterations(llm calls) before the agent will stopmax_execution_time: Maximum time (in seconds) for the agent thinking process.tools: extend agent capabilities by providing access to custom functionality, there are built-in tools such ascurrent_date,google_searchandweb_scraperand custom tools (http, code, function)
task_id. To learn more see Agents via the API2
Tools
To define custom business logic for HR operations and access add external systems, APIs, and custom functionality you can use Tools such as:Add the function above as payload string to the Agent:Expected output:
- HTTP Tools: Integrate with external APIs (e.g., weather, search, CRM).
- Function Tools: Inject custom logic via the OpenAI function-calling schema.
- Code Tools: Run small snippets of Python in secure sandboxes for data transformation.
your_script.py
Tip: Converting Python Code to Payload StringTo convert your Python code into a JSON-safe string for the payload, use this shell command:
cat your_script.py | jq -Rs '.' 3
Memory and Context
To remember employee preferences and store conversation history we will add in the next step the Expected output:Expected outputTo learn about other use cases of memory stores see Using Memory Stores
memory_stores, that would help persist context across sessions.- Create a memory store
- Run HR Agent with memory store
- List memories in the memory store
4
Knowledge Bases
Make sure that your Agent grounds its responses based on your company policies. To do that we will add a Knowledge Base for contextual accuracy.Expected output
- Create a Knowledge Base
- Upload a file
Orq.ai supports document of the following format: TXT, PDF, DOCX, CSV, XML
- Create a datasource
A Datasource is the integral part of the Knowledge Base, it holds chunks of data within which a model can search and make retrievals returned within a RAG use case. A Knowledge base can hold any number of Datasources.
- Integrate Knowledge Base into the Agent
5
Multi-Agent systems
Next, we define aExpected output:Full code snippet creating an orchestrator with :Expected output:Invoking the orchestratorExpected output:
team_of_agents with specialized roles and task delegation. Above we already defined the main Agent, which is hr-policy-agent, which calculates PTO. Next, we add a sub-agent: benefits_agent that handles questions related to health benefits and retirement plan inquiries.- Create sub-agent:
benefits_agent
-
**Create Orchestrator **
We have created two agents with the following reference keys 2.
hr_benefits_specialist: answers general HR questions (benefits, sick leave etc.) 2.hr_policy_agent: calculates PTO remaining based on starting date We need to manage them via orchestrator that will delegate the tasks to one of the agents. To do that we need to define ateam_of_agentsarray in your orchestrator agent configuration:
- Required Tools: Add
retrieve_agentsandcall_sub_agenttools to your orchestrator’s configuration to enable sub-agent discovery and delegation
Troubleshooting & Best Practices
Common Issues & Solutions
Common Issues & Solutions
Knowledge Base Not Returning Results
- Confirm datasource creation completed successfully
- Verify
query_knowledge_basetool is enabled - Check
thresholdvalue (lower = more permissive, try 0.5 instead of 0.7) - Ensure documents were successfully chunked and embedded
- Verify both
retrieve_agentsandcall_sub_agenttools are enabled - Check
team_of_agentsarray includes correct agent keys - Ensure sub-agents exist and have matching keys
- Review orchestrator instructions for clarity on routing logic
Best Practices for Production
Best Practices for Production
1. Error Handling & Resilience2. Rate Limiting & Timeouts
- Set appropriate
max_execution_time(300s for simple tasks, 600s for complex) - Implement exponential backoff for retries
- Monitor API usage to stay within quotas
- Track token usage and costs per agent/user
- Monitor average response times
- Set up alerts for failed executions
- Review agent conversation histories periodically
Production Considerations
Production Considerations
Cost Optimization
- Set
max_iterationsconservatively (5-8 for most use cases) - Use cheaper models (e.g.,
gpt-4o-mini) for sub-agents handling simple tasks - Monitor and optimize tool usage patterns
- Implement response caching for common queries
- Use agent
keyversioning (e.g.,hr_orchestrator_v2) - Test changes in non-production environments first
- Maintain backward compatibility when updating tools
Performance Optimization Tips
Performance Optimization Tips
Reduce Latency
- Minimize
max_iterationsto prevent unnecessary reasoning loops - Use streaming for real-time user feedback
- Pre-load frequently accessed knowledge base content
- Cache agent configurations where possible
- Write clear, specific agent instructions with examples
- Use higher quality embedding models for knowledge bases (
text-embedding-3-large) - Increase
top_kfor knowledge base queries if retrieval seems incomplete - Regularly review and refine agent instructions based on user feedback
- Keep instructions concise but clear
- Limit conversation history length in memory stores
- Use smaller models for simple sub-agents
- Implement smart context pruning for long conversations
Conclusion
You’ve built a production-ready HR management system that showcases the power of Orq.ai’s **Multi-Agent architecture **withbenefits_agentand hr-policy-agent. Starting from a simple agent, you’ve progressed to a two-agent orchestration with persistent memory, knowledge base grounding, custom tools, and enterprise-grade observability through one unified API.
To learn more explore the documentation: