Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,45 @@ Place it before imports with one blank line after.

### Python Conventions

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

### Type Hints - NEVER Use `Any`

**CRITICAL: Never use `typing.Any` in this codebase.** Using `Any` defeats the purpose of type checking and can hide bugs. Instead:

1. **Use actual types from external SDKs** - When integrating with external libraries (OpenAI, LangChain, etc.), import and use their actual types:
```python
from agents.memory import Session
from agents.items import TResponseInputItem

async def send_chat_history(self, session: Session) -> OperationResult:
...
```

2. **Use `Union` for known possible types**:
```python
from typing import Union
MessageType = Union[UserMessage, AssistantMessage, SystemMessage, Dict[str, object]]
```

3. **Use `object` for truly unknown types** that you only pass through:
```python
def log_item(item: object) -> None: ...
```

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.

**Why this matters:**
- `Any` disables all type checking for that variable
- Bugs that type checkers would catch go unnoticed
- Code readability suffers - developers don't know what types to expect
- Using actual SDK types provides better IDE support and ensures compatibility
- This applies to both production code AND test files

## CI/CD

The `.github/workflows/ci.yml` pipeline:
Expand Down
44 changes: 43 additions & 1 deletion docs/design.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,51 @@ Framework-specific adapters for MCP tool integration:
|---------|---------|------------|
| `extensions-agentframework` | Adapt MCP tools to Microsoft Agents SDK | [design.md](../libraries/microsoft-agents-a365-tooling-extensions-agentframework/docs/design.md) |
| `extensions-azureaifoundry` | Azure AI Foundry tool integration | [design.md](../libraries/microsoft-agents-a365-tooling-extensions-azureaifoundry/docs/design.md) |
| `extensions-openai` | OpenAI function calling integration | [design.md](../libraries/microsoft-agents-a365-tooling-extensions-openai/docs/design.md) |
| `extensions-openai` | OpenAI function calling integration and chat history | [design.md](../libraries/microsoft-agents-a365-tooling-extensions-openai/docs/design.md) |
| `extensions-semantickernel` | Semantic Kernel plugin integration | [design.md](../libraries/microsoft-agents-a365-tooling-extensions-semantickernel/docs/design.md) |

#### OpenAI Extension: Chat History API

The OpenAI tooling extension provides methods to send chat history to the MCP platform for real-time threat protection:

**Key Classes:**

| Class | Purpose |
|-------|---------|
| `McpToolRegistrationService` | MCP tool registration and chat history management |

**Methods:**

| Method | Purpose |
|--------|---------|
| `send_chat_history(turn_context, session, limit, options)` | Extract messages from OpenAI Session and send to MCP platform |
| `send_chat_history_messages(turn_context, messages, options)` | Send a list of OpenAI TResponseInputItem messages to MCP platform |

**Usage Example:**

```python
from agents import Agent, Runner
from microsoft_agents_a365.tooling.extensions.openai import McpToolRegistrationService

service = McpToolRegistrationService()
agent = Agent(name="my-agent", model="gpt-4")

# In your agent handler:
async with Runner.run(agent, messages) as result:
session = result.session

# Option 1: Send from Session object
op_result = await service.send_chat_history(turn_context, session)

# Option 2: Send from message list
op_result = await service.send_chat_history_messages(turn_context, messages)

if op_result.succeeded:
print("Chat history sent successfully")
```

The methods convert OpenAI message types to `ChatHistoryMessage` format and delegate to the core `McpToolServerConfigurationService.send_chat_history()` method.

### 6. Notifications (`microsoft-agents-a365-notifications`)

> **Detailed documentation**: [libraries/microsoft-agents-a365-notifications/docs/design.md](../libraries/microsoft-agents-a365-notifications/docs/design.md)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,21 @@
# Licensed under the MIT License.

"""
OpenAI extensions for Microsoft Agent 365 Tooling SDK
OpenAI extensions for Microsoft Agent 365 Tooling SDK.

Tooling and utilities specifically for OpenAI framework integration.
Provides OpenAI-specific helper utilities.
Provides OpenAI-specific helper utilities including:
- McpToolRegistrationService: Service for MCP tool registration and chat history management

For type hints, use the types directly from the OpenAI Agents SDK:
- agents.memory.Session: Protocol for session objects
- agents.items.TResponseInputItem: Type for input message items
"""

from .mcp_tool_registration_service import McpToolRegistrationService

__version__ = "1.0.0"

__all__ = [
"McpToolRegistrationService",
]
Loading