Skip to content

Commit 05c1608

Browse files
author
Johan Broberg
committed
Implement API for OpenAI chat history
1 parent acd40c3 commit 05c1608

12 files changed

Lines changed: 2157 additions & 12 deletions

File tree

CLAUDE.md

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,45 @@ Place it before imports with one blank line after.
168168

169169
### Python Conventions
170170

171-
- Type hints preferred (Pydantic models heavily used)
171+
- Type hints required on all function parameters and return types
172172
- Async/await patterns for I/O operations
173173
- Use explicit `None` checks: `if x is not None:` not `if x:`
174174
- Local imports should be moved to top of file
175175
- Return defensive copies of mutable data to protect singletons
176176

177+
### Type Hints - NEVER Use `Any`
178+
179+
**CRITICAL: Never use `typing.Any` in this codebase.** Using `Any` defeats the purpose of type checking and can hide bugs. Instead:
180+
181+
1. **Use actual types from external SDKs** - When integrating with external libraries (OpenAI, LangChain, etc.), import and use their actual types:
182+
```python
183+
from agents.memory import Session
184+
from agents.items import TResponseInputItem
185+
186+
async def send_chat_history_async(self, session: Session) -> OperationResult:
187+
...
188+
```
189+
190+
2. **Use `Union` for known possible types**:
191+
```python
192+
from typing import Union
193+
MessageType = Union[UserMessage, AssistantMessage, SystemMessage, Dict[str, object]]
194+
```
195+
196+
3. **Use `object` for truly unknown types** that you only pass through:
197+
```python
198+
def log_item(item: object) -> None: ...
199+
```
200+
201+
4. **Use `Protocol` only as a last resort** - If external types cannot be found or imported, define a Protocol. However, **confirm with the developer first** before proceeding with this approach, as it may indicate a missing dependency or incorrect understanding of the external API.
202+
203+
**Why this matters:**
204+
- `Any` disables all type checking for that variable
205+
- Bugs that type checkers would catch go unnoticed
206+
- Code readability suffers - developers don't know what types to expect
207+
- Using actual SDK types provides better IDE support and ensures compatibility
208+
- This applies to both production code AND test files
209+
177210
## CI/CD
178211

179212
The `.github/workflows/ci.yml` pipeline:

docs/prd/openai-send-chat-history-api.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,52 @@ The API SHALL extract text content following this priority:
226226
| Type hints | Complete type annotations (PEP 484) |
227227
| Pydantic version | ≥2.0 (for model validation) |
228228

229+
### 5.1.1 Type Hints - NEVER Use `Any`
230+
231+
**CRITICAL**: The use of `typing.Any` is **strictly forbidden** in this codebase. Using `Any` defeats the purpose of type checking and can hide bugs.
232+
233+
**Required alternatives (in order of preference):**
234+
235+
| Instead of `Any` | Use |
236+
|------------------|-----|
237+
| External SDK types | Import and use actual types from the SDK (e.g., `Session`, `TResponseInputItem`) |
238+
| Multiple known types | `Union[Type1, Type2, ...]` |
239+
| Pass-through data | `object` |
240+
| Dictionary values | `Dict[str, object]` or specific types |
241+
| Unknown external types (last resort) | `Protocol` - but confirm with developer first |
242+
243+
**Preferred approach - Use actual SDK types:**
244+
245+
```python
246+
from agents.memory import Session
247+
from agents.items import TResponseInputItem
248+
249+
async def send_chat_history_async(
250+
self,
251+
turn_context: TurnContext,
252+
session: Session, # Use actual SDK type
253+
) -> OperationResult:
254+
...
255+
256+
async def send_chat_history_messages_async(
257+
self,
258+
turn_context: TurnContext,
259+
messages: List[TResponseInputItem], # Use actual SDK type
260+
) -> OperationResult:
261+
...
262+
```
263+
264+
**Why actual SDK types are preferred:**
265+
- Better IDE support (autocomplete, type checking)
266+
- Ensures compatibility with the external SDK
267+
- Less maintenance burden (no custom protocols to keep in sync)
268+
- Clearer intent for developers reading the code
269+
270+
**When to use Protocol (last resort only):**
271+
If external types cannot be found or imported, a `Protocol` may be defined. However, this should be rare and requires confirmation with the developer before proceeding, as it may indicate a missing dependency or incorrect understanding of the external API.
272+
273+
This requirement applies to both production code AND test files.
274+
229275
### 5.2 OpenAI SDK Compatibility
230276

231277
| Requirement | Specification |

libraries/microsoft-agents-a365-tooling-extensions-openai/microsoft_agents_a365/tooling/extensions/openai/__init__.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,21 @@
22
# Licensed under the MIT License.
33

44
"""
5-
OpenAI extensions for Microsoft Agent 365 Tooling SDK
5+
OpenAI extensions for Microsoft Agent 365 Tooling SDK.
66
77
Tooling and utilities specifically for OpenAI framework integration.
8-
Provides OpenAI-specific helper utilities.
8+
Provides OpenAI-specific helper utilities including:
9+
- McpToolRegistrationService: Service for MCP tool registration and chat history management
10+
11+
For type hints, use the types directly from the OpenAI Agents SDK:
12+
- agents.memory.Session: Protocol for session objects
13+
- agents.items.TResponseInputItem: Type for input message items
914
"""
1015

16+
from .mcp_tool_registration_service import McpToolRegistrationService
17+
1118
__version__ = "1.0.0"
19+
20+
__all__ = [
21+
"McpToolRegistrationService",
22+
]

0 commit comments

Comments
 (0)