Skip to content

API Reference parrot.interfaces.hierarchy

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.interfaces.hierarchy

View source

Utilities for managing the employee hierarchy stored in ArangoDB.

Alias CacheMixin

Re-exported from parrot.memory.cache.CacheMixin.

Alias EMPLOYEES_TABLE

Re-exported from parrot.conf.EMPLOYEES_TABLE.

Class Employee

Employee Information

Parameter Type Default Description
employee_id str
associate_oid str
first_name str
last_name str
display_name str
email str
job_code str
position_id str
department str
program str
reports_to Optional[str]

Fields:

Field Type Default Description
employee_id str
associate_oid str
first_name str
last_name str
display_name str
email str
job_code str
position_id str
department str
program str
reports_to Optional[str]

Class EmployeeHierarchyManager

Hierarchy Manager using ArangoDB to store employees and their reporting structure. It supports importing from PostgreSQL, inserting individual employees, and performing hierarchical queries like finding superiors, subordinates, and colleagues.

Parameter Type Default Description
arango_host 'localhost'
arango_port 8529
db_name 'company_db'
username 'root'
password ''
**kwargs {}

Attributes:

Attribute Type Description
employees_collection Name of the collection for employee vertices.

Method EmployeeHierarchyManager.connection

Async context manager for ArangoDB connection

connection()

Method EmployeeHierarchyManager.drop_all_indexes

Drop all user-defined indexes from the employees collection. Useful for troubleshooting or resetting the collection.

drop_all_indexes()

Method EmployeeHierarchyManager.import_from_postgres

Import employees from PostgreSQL

import_from_postgres()

Method EmployeeHierarchyManager.truncate_hierarchy

Truncate employees and reports_to collections.

This:

  • Deletes all employee vertices.
  • Deletes all reports_to edges.
  • Keeps:
    • Collections
    • Indexes
    • Graph definition

Use this when you want a clean reload from PostgreSQL.

truncate_hierarchy() -> None

Method EmployeeHierarchyManager.insert_employee

Insert an individual employee

insert_employee(employee: Employee) -> str

Parameter Type Default Description
employee Employee

Returns: str

Method EmployeeHierarchyManager.does_report_to

Check if employee_oid reports directly or indirectly to boss_oid.

does_report_to(employee_oid: str, boss_oid: str, limit: int = 1) -> bool

Parameter Type Default Description
employee_oid str Associate OID of the employee
boss_oid str Associate OID of the boss
limit int 1

Returns: bool — True if employee reports to boss, False otherwise

Method EmployeeHierarchyManager.get_all_superiors

Return all superiors of an employee up to the CEO.

get_all_superiors(employee_oid: str) -> List[Dict]

Parameter Type Default Description
employee_oid str

Returns: List[Dict] — List ordered from direct boss to CEO

Method EmployeeHierarchyManager.get_direct_reports

Return direct reports of a boss

get_direct_reports(boss_oid: str) -> List[Dict]

Parameter Type Default Description
boss_oid str

Returns: List[Dict]

Method EmployeeHierarchyManager.get_all_subordinates

Return all subordinates (direct and indirect) of a boss

get_all_subordinates(boss_oid: str, max_depth: int = 10) -> List[Dict]

Parameter Type Default Description
boss_oid str
max_depth int 10

Returns: List[Dict]

Method EmployeeHierarchyManager.get_org_chart

Build the complete org chart as a hierarchical tree

get_org_chart(root_oid: Optional[str] = None) -> Dict

Parameter Type Default Description
root_oid Optional[str] None If specified, builds the tree from that node

Returns: Dict — Hierarchical tree as a list of dictionaries

Method EmployeeHierarchyManager.get_colleagues

Return colleagues (employees who share the same boss)

get_colleagues(employee_oid: str) -> List[Dict[str, Any]]

Parameter Type Default Description
employee_oid str Associate OID of the employee

Returns: List[Dict[str, Any]] — List of colleagues

Method EmployeeHierarchyManager.get_employee_info

Get detailed information about an employee.

Example:

manager = EmployeeHierarchyManager(...)

# First call - query ArangoDB
info = await manager.get_employee_info('E003')

# Second call - from Redis cache
info = await manager.get_employee_info('E003')  # ⚡

get_employee_info(employee_oid: str) -> Optional[Dict]

Parameter Type Default Description
employee_oid str Employee ID (associate_oid)

Returns: Optional[Dict] — Dict with employee information or None if not found {

'employee_id': str, 'associate_oid': str, 'display_name': str, 'first_name': str, 'last_name': str, 'email': str, 'department': str, 'program': str, 'position_id': str, 'job_code': str }

Method EmployeeHierarchyManager.get_department_context

Get a summary of the employee's department context, including superiors, colleagues, direct reports, and all subordinates.

get_department_context(employee_oid: str) -> Dict

Parameter Type Default Description
employee_oid str

Returns: Dict

Method EmployeeHierarchyManager.are_in_same_department

Check if two employees are in the same department (broader than colleagues).

are_in_same_department(employee1: str, employee2: str) -> bool

Parameter Type Default Description
employee1 str First employee's ID
employee2 str Second employee's ID

Returns: bool — True if in same department, False otherwise

Method EmployeeHierarchyManager.get_team_members

Get all team members under a manager.

get_team_members(manager_id: str, include_all_levels: bool = False) -> List[Dict[str, Any]]

Parameter Type Default Description
manager_id str Manager's ID
include_all_levels bool False If True, include all subordinates recursively. If False, only direct reports.

Returns: List[Dict[str, Any]] — List of team member information

Method EmployeeHierarchyManager.are_colleagues

Check if two employees are colleagues (same boss, same level).

Two employees are considered colleagues if:

  1. They have the same direct manager
  2. They are at the same hierarchical level
  3. They are not the same person

are_colleagues(employee1: str, employee2: str) -> bool

Parameter Type Default Description
employee1 str First employee's ID
employee2 str Second employee's ID

Returns: bool — True if they are colleagues, False otherwise

Method EmployeeHierarchyManager.is_manager

Check if the given employee is a manager (has direct reports).

is_manager(employee_oid: str) -> bool

Parameter Type Default Description
employee_oid str Employee ID to check

Returns: bool — True if the employee is a manager, False otherwise

Method EmployeeHierarchyManager.get_closest_common_boss

Find the closest common boss between two employees.

get_closest_common_boss(employee1: str, employee2: str) -> Optional[Dict]

Parameter Type Default Description
employee1 str First employee's ID
employee2 str Second employee's ID

Returns: Optional[Dict] — Dict with common boss information or None if not found

Method EmployeeHierarchyManager.is_boss_of

Check if boss_oid is a boss (direct or indirect) of employee_oid.

is_boss_of(employee_oid: str, boss_oid: str, direct_only: bool = False) -> Dict[str, Any]

Parameter Type Default Description
employee_oid str Employee's ID
boss_oid str Boss's ID
direct_only bool False If True, check only direct reporting (level 1) If False, check any level in hierarchy

Returns: Dict[str, Any] — Dict with relationship details: { 'is_manager': bool, 'is_direct_manager': bool, 'level': int (0 if not manager, 1 for direct, 2+ for indirect), 'path': list of employee IDs from employee to manager }

Method EmployeeHierarchyManager.is_subordinate

Check if employee_oid is a subordinate of manager_oid. This is the inverse of is_boss_of().

is_subordinate(employee_oid: str, manager_oid: str, direct_only: bool = False) -> Dict[str, Any]

Parameter Type Default Description
employee_oid str Employee's ID
manager_oid str Potential manager's ID
direct_only bool False If True, check only direct reporting

Returns: Dict[str, Any] — Dict with relationship details

Method EmployeeHierarchyManager.get_relationship

Get the complete relationship between two employees.

get_relationship(employee1: str, employee2: str) -> Dict[str, Any]

Parameter Type Default Description
employee1 str First employee's ID
employee2 str Second employee's ID

Returns: Dict[str, Any] — Comprehensive relationship information

Method EmployeeHierarchyManager.check_management_chain

Check if target_manager_id is anywhere in employee's management chain. Returns the complete path and level if found.

check_management_chain(employee_id: str, target_manager_id: str) -> Dict[str, Any]

Parameter Type Default Description
employee_id str Employee's ID
target_manager_id str Manager to search for in chain

Returns: Dict[str, Any] — Dict with chain details

Attribute P

Attribute T

Alias cached_query

Re-exported from parrot.memory.cache.cached_query.

Alias default_dsn

Re-exported from parrot.conf.default_dsn.

Alias lazy_import

Re-exported from parrot._imports.lazy_import.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally