Skip to main content

TL;DR

  • Build HR management agents using Orq.ai Python SDK
  • Connect tools (Python custom functions)
  • Enable memory for context-aware conversations
  • Add Knowledge Base with company policy documents
  • Create multi-agent teams with specialized roles (benefits, PTO calculator)
Working from an IDE? Build these agents from a coding assistant via the Orq MCP.

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

  1. 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.
  2. Persistent Memory & Personalization Unlike stateless API calls, Agents maintain conversation history and user preferences across sessions through Memory Stores, enabling truly personalized employee experiences.
  3. 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

  1. Python 3.8+ python or higher
  2. An API Key ready to be used with the API.
  3. Orq.ai SDK installed
  4. A workspace with a Project named agentsand Folder.
  5. Copy the path property ( You will use it in code as path="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 Metadata
  • role : description and instructions
  • description : short description of agent’s purpose
  • instructions : instructions for the agent behaviour
Configuration parameters
  • model: choose from providers e.g. openai/gpt-4o, anthropic/claude-sonnet-4-6 and set the number of retries on specific error codes
  • settings : Configuration settings for the agent’s behavior, such as:
    • max_iterations : Maximum iterations(llm calls) before the agent will stop
    • max_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 as current_date , google_search and web_scraper and custom tools (http, code, function)
Run the code below to create an agent:
Expected output:
Next, you need to invoke a response from a newly created agent:
Expected output
After receiving a response, continue the conversation by passing the response id as previous_response_id in the next request. The agent maintains full context from previous exchanges. To learn more see Agents via the API
Expected output:
2

Tools

To define custom business logic for HR operations and access add external systems, APIs, and custom functionality you can use Tools such as:
  • 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.
  • MCP Tools: Connect an external MCP server so the agent can call its tools. See MCP Tool.
To see a full reference of basic tools see Tools with AgentsFirst you need to define function calculating remaining PTO:
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 '.'
Add the function above as payload string to the Agent:
Expected output:
3

Memory and Context

To remember employee preferences and store conversation history we will add in the next step the memory_stores, that would help persist context across sessions.
  1. Create a memory store
  1. Run HR Agent with memory store
Expected output:
  1. List memories in the memory store
Memory Store contains Memories (representing entities), which in turn contain documents (information). Here is an example look up of memories in a memory store:
Expected output
To learn about other use cases of memory stores see Using Memory Stores
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.
  1. Create a Knowledge Base
  1. Upload a file
Orq.ai supports document of the following format: TXT, PDF, DOCX, CSV, XML
Make sure to change the file path
  1. 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.
  1. Integrate Knowledge Base into the Agent
Expected output
5

Multi-Agent systems

Next, we define ateam_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.
  1. Create sub-agent:benefits_agent
Expected output:
  1. **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_agents array in your orchestrator agent configuration:
Full code snippet creating an orchestrator with :
  • Required Tools: Add retrieve_agents and call_sub_agent tools to your orchestrator’s configuration to enable sub-agent discovery and delegation
Expected output:
Invoking the orchestrator
Expected output:

Troubleshooting & Best Practices

Knowledge Base Not Returning Results
  • Confirm datasource creation completed successfully
  • Verify query_knowledge_base tool is enabled
  • Check threshold value (lower = more permissive, try 0.5 instead of 0.7)
  • Ensure documents were successfully chunked and embedded
Sub-Agent Delegation Issues
  • Verify both retrieve_agents and call_sub_agent tools are enabled
  • Check team_of_agents array includes correct agent keys
  • Ensure sub-agents exist and have matching keys
  • Review orchestrator instructions for clarity on routing logic
1. Error Handling & Resilience
2. 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
3. Monitoring & Observability
  • Track token usage and costs per agent/user
  • Monitor average response times
  • Set up alerts for failed executions
  • Review agent conversation histories periodically
Cost Optimization
  • Set max_iterations conservatively (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
Versioning & Updates
  • Use agent key versioning (e.g., hr_orchestrator_v2)
  • Test changes in non-production environments first
  • Maintain backward compatibility when updating tools
Reduce Latency
  • Minimize max_iterations to prevent unnecessary reasoning loops
  • Use streaming for real-time user feedback
  • Pre-load frequently accessed knowledge base content
  • Cache agent configurations where possible
Improve Accuracy
  • Write clear, specific agent instructions with examples
  • Use higher quality embedding models for knowledge bases (text-embedding-3-large)
  • Increase top_k for knowledge base queries if retrieval seems incomplete
  • Regularly review and refine agent instructions based on user feedback
Token Efficiency
  • 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 **with benefits_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:

Tools with Agents

Attaching Files with Agents

Knowledge Bases with Agents

Memory Management with Agents

Multi-Agent Workflows

Build with the Orq MCP