0% found this document useful (0 votes)
11 views4 pages

API Contracts for Office Agent System

The document outlines the API contracts for the Office Agent System, detailing the input/output schemas for agents, REST API endpoints for chat, authentication, agent listing, and health checks. It specifies routing rules for agent requests and inter-agent communication protocols, as well as error codes for handling various issues. Additionally, it mentions future webhook events for external integrations related to bookings.

Uploaded by

Diep Phan
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views4 pages

API Contracts for Office Agent System

The document outlines the API contracts for the Office Agent System, detailing the input/output schemas for agents, REST API endpoints for chat, authentication, agent listing, and health checks. It specifies routing rules for agent requests and inter-agent communication protocols, as well as error codes for handling various issues. Additionally, it mentions future webhook events for external integrations related to bookings.

Uploaded by

Diep Phan
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

# API Contracts

This document defines the contracts between components in the Office Agent System.

## Agent Input/Output Contract

All agents must implement the `run_agent` function with this signature:

```python
async def run_agent(input_data: AgentInputSchema) -> AgentOutputSchema
```

### AgentInputSchema

```python
class AgentInputSchema(BaseModel):
query: str # User's query
user_id: str # User identifier
session_id: Optional[str] = None # Session for context
context: Optional[Dict[str, Any]] = None # Additional context
conversation_history: Optional[List[Dict]] = None # Previous messages
```

### AgentOutputSchema

```python
class AgentOutputSchema(BaseModel):
result: str # Agent's response
agent_name: str # Agent identifier
actions_taken: List[AgentAction] = [] # Actions performed
needs_followup: bool = False # Needs user response
followup_questions: Optional[List[str]] = None # Suggested questions
confidence_score: Optional[float] = None # Response confidence
metadata: Optional[Dict[str, Any]] = None # Additional data
```

## REST API Endpoints

### POST /api/v1/chat

Main chat endpoint for interacting with the agent system.

**Request:**
```json
{
"query": "Book a meeting room for tomorrow",
"session_id": "optional-session-id",
"context": {}
}
```

**Response:**
```json
{
"response": "I found several rooms available...",
"session_id": "abc123",
"agent_used": "booking_facility",
"actions": [
{
"action_type": "tool_call",
"description": "Searched for available rooms",
"tool_used": "find_available_rooms",
"result": "Found 3 rooms",
"success": true
}
],
"suggestions": ["Would you like to book one?"],
"timestamp": "2025-01-16T10:30:00Z"
}
```

### POST /api/v1/auth/login

Obtain an access token.

**Request:**
```json
{
"username": "[Link]",
"password": "password123"
}
```

**Response:**
```json
{
"access_token": "eyJhbGciOiJIUzI1NiIs...",
"token_type": "bearer"
}
```

### GET /api/v1/agents

List available agents.

**Response:**
```json
{
"agents": [
"booking_meeting",
"booking_facility",
"booking_tea",
"booking_guest",
"qa_document",
"event_finder"
]
}
```

### POST /api/v1/agents/{agent_name}/invoke

Invoke a specific agent directly.

**Request:**
```json
{
"query": "What rooms are available?",
"session_id": "optional"
}
```

**Response:** Same as `/chat` endpoint.

### GET /api/v1/health

Health check endpoint.

**Response:**
```json
{
"status": "ok",
"version": "1.0.0",
"timestamp": "2025-01-16T10:30:00Z",
"services": {
"orchestrator": true,
"agents": true
}
}
```

## Routing Contract

The orchestrator routes requests based on this structure:

### RoutingDecision

```python
class RoutingDecision(BaseModel):
primary_agent: str # Main agent to handle request
secondary_agents: List[str] # Supporting agents
reasoning: str # Why this routing was chosen
confidence: float = 1.0 # Routing confidence
```

### Routing Rules

| Request Type | Primary Agent | Secondary Agents |


|--------------|---------------|------------------|
| Meeting scheduling | booking_meeting | booking_facility, booking_tea |
| Room booking | booking_facility | - |
| Refreshments | booking_tea | - |
| Guest registration | booking_guest | - |
| Policy questions | qa_document | - |
| Event search | event_finder | - |
| Meeting with guests | booking_meeting | booking_guest, booking_facility |

## Inter-Agent Communication

When agents need to coordinate, they pass context through the orchestrator:

```python
# Primary agent result
primary_result = await primary_agent(input_data)

# Secondary agents receive primary result in context


secondary_input = AgentInputSchema(
query=input_data.query,
user_id=input_data.user_id,
context={"primary_result": primary_result.result}
)
secondary_result = await secondary_agent(secondary_input)
```

## Error Codes

| Code | Description |
|------|-------------|
| 400 | Bad request - invalid input |
| 401 | Unauthorized - invalid/missing token |
| 403 | Forbidden - insufficient permissions |
| 404 | Not found - agent/resource not found |
| 409 | Conflict - booking conflict |
| 500 | Internal error - agent/system failure |

## Webhook Events (Future)

The system can emit events for external integrations:

```json
{
"event_type": "[Link]",
"timestamp": "2025-01-16T10:30:00Z",
"data": {
"booking_id": "booking_123",
"booking_type": "facility",
"user_id": "user_456"
}
}
```

Common questions

Powered by AI

The system defines error codes such as 400 for invalid input (Bad Request), 401 for missing or invalid tokens (Unauthorized), 403 for insufficient permissions (Forbidden), 404 for resources not found (Not Found), 409 for conflicts, particularly in bookings (Conflict), and 500 indicating agent or system failure (Internal Error). These codes provide vital feedback on operations, signalling issues with request formulation, authentication, authorization, resource availability, data conflicts, and system reliability. Monitoring these codes can help maintain smooth operation and swiftly address any disruptions or faults .

The AgentOutputSchema includes fields such as result, agent_name, actions_taken, needs_followup, followup_questions, confidence_score, and metadata. Potential pitfalls include a low confidence_score leading to less reliable or inaccurate responses, inappropriate suggestions in followup_questions that may not address user needs, or errors in actions_taken which could result in incorrect actions being performed. These issues could lead to user dissatisfaction if queries are mishandled or incorrect information is provided, impacting the efficiency and reliability perceived by users .

Inter-agent communication is facilitated by the orchestrator, which allows agents to use the outcome of a primary agent's task in the context for secondary agents. This method of passing context via the orchestrator ensures that all relevant data is available and utilized appropriately, promoting seamless cooperation among agents. By coordinating their tasks effectively, this framework enhances the system's overall efficiency by preventing duplication of efforts and ensuring that agents work towards a common outcome efficiently .

The AgentInputSchema consists of the components such as query, user_id, session_id, context, and conversation_history. These elements serve specific roles: 'query' is the user's request to the agent; 'user_id' identifies the user making the request; 'session_id' tracks the session context; 'context' holds additional optional information like previous interactions or relevant data; and 'conversation_history' provides a trail of prior exchanges that help the agent tailor its responses based on past interactions. Together, these components enable the agent to process requests with context and continuity, ensuring a more coherent interaction .

The POST /api/v1/auth/login endpoint poses risks such as unauthorized access through credential theft or brute force attacks. These risks can potentially compromise user data and system integrity if unauthorized users obtain access tokens. Mitigation strategies include implementing strong password policies, rate limiting, multi-factor authentication, and ensuring secure transmission of credentials using HTTPS. Additionally, employing robust monitoring and anomaly detection can help identify and respond to unauthorized attempts effectively .

In meeting with guests scenarios, the booking_meeting agent acts as the primary agent to handle the coordination of the meeting, while the booking_guest and booking_facility agents serve as secondary agents. The booking_guest agent ensures that guest needs are addressed, while the booking_facility agent deals with logistical or facility-related requirements. This division of labor ensures thorough and efficient handling of complex requests by enabling specialized agents to manage different aspects of the event, enhancing completeness and precision in arranging such meetings .

The 'tool_call' action type in the agent's action list signifies an action where the agent utilized a specific tool to perform a task, such as searching for available rooms in response to a booking query. The expected outcome is that the agent successfully uses the tool to retrieve and provide pertinent information. This action contributes to fulfilling user requests by leveraging backend capabilities, ensuring accurate and efficient handling of user queries, and ultimately improving user satisfaction through streamlined and effective execution of tasks .

Using the POST /api/v1/agents/{agent_name}/invoke endpoint allows direct invocation of a specified agent, providing targeted interactions without the need for the decision-making process of choosing the appropriate agent. This enables more customized handling and possibly faster response times when the user knows which agent to utilize. However, it lacks the flexibility of the POST /api/v1/chat endpoint, which dynamically determines the appropriate agent based on the request type, potentially offering more comprehensive solutions when multiple agents could address a query. This trade-off between specificity and dynamic adaptability reflects different user needs and use cases .

The orchestrator determines the primary agent based on predefined routing rules linked to the type of request, as shown in the routing structure. For instance, a request for room booking would directly prompt the assignment of 'booking_facility' as the primary agent. Secondary agents may be involved based on the complexity of the task and predefined scenarios that require additional support, such as booking refreshments or coordinating guest services, which is done to enhance the service or provide additional information .

The POST /api/v1/chat endpoint allows users to interact with the agent system by submitting queries. The request includes the user's query, and optionally a session_id and context, ensuring tailored and context-sensitive responses. The response from the agent includes key elements such as a session ID for request tracking, a response from an aligned agent, actions performed during the processing of the query, suggestions for follow-up actions or questions, and a timestamp. This comprehensive exchange fosters an efficient and user-friendly interaction experience .

You might also like