Skip to content

Add Deadlock API schema fetching tool and enhance API documentation#9

Merged
raimannma merged 1 commit intomasterfrom
claude/deadlock-api-docs-schema-pj2LE
Feb 6, 2026
Merged

Add Deadlock API schema fetching tool and enhance API documentation#9
raimannma merged 1 commit intomasterfrom
claude/deadlock-api-docs-schema-pj2LE

Conversation

@raimannma
Copy link
Member

Summary

This PR adds a new DeadlockAPISchemaFetchTool that allows the AI agent to fetch and inspect OpenAPI schemas for the Deadlock APIs, enabling it to answer detailed questions about available endpoints and parameters. It also enhances the Deadlock API documentation with comprehensive resource information and improves the API info structure.

Key Changes

  • New Schema Fetch Tool: Added DeadlockAPISchemaFetchTool class that fetches OpenAPI specifications for either the Game Data API or Assets API, with proper error handling and retry logic
  • Enhanced API Info: Restructured DEADLOCK_API_INFO dictionary with:
    • New "overview" section describing both APIs
    • Expanded descriptions for data_api and assets_api with specific use cases
    • Added "docs" links to Swagger documentation for both APIs
    • Improved community link descriptions (GitHub, Discord, Patreon)
  • OpenAPI Spec URLs: Added OPENAPI_SPEC_URLS constant for centralized management of schema endpoints
  • Agent Knowledge Base: Updated agent.py with comprehensive Deadlock API documentation including guidance on when to use deadlock_api_schema vs deadlock_api_info tools
  • Tool Registry: Integrated the new schema fetch tool into the tool registry with lazy initialization and proper cleanup
  • Comprehensive Tests: Added 15+ test cases covering:
    • Tool initialization and definition
    • Schema fetching for both APIs
    • Error handling (HTTP errors, network errors, invalid inputs)
    • SSE event emission
    • Result summary formatting
    • Constant validation

Implementation Details

  • The schema fetch tool uses httpx.AsyncClient with configurable timeout and automatic retry logic
  • Proper error handling with custom OpenAPIConnectionError exceptions
  • Tool is properly integrated into the registry with lazy initialization and async cleanup
  • All existing tests remain passing; formatting improvements made to patreon_test.py

https://claude.ai/code/session_017pU3sCe7ku3xp7as1VXnkp

- Enrich DEADLOCK_API_INFO with overview, docs links, and detailed
  descriptions for both Game Data and Assets APIs
- Add DeadlockAPISchemaFetchTool that fetches OpenAPI specs for either
  the data API or assets API so the agent can answer detailed questions
  about available endpoints, parameters, and response formats
- Register the new tool in ToolRegistry with proper lifecycle management
- Update system prompt with Deadlock API section including all resource
  links and guidance to use the schema tool for API usage questions
- Add comprehensive tests for both the info tool and schema fetch tool

https://claude.ai/code/session_017pU3sCe7ku3xp7as1VXnkp
Copilot AI review requested due to automatic review settings February 6, 2026 11:04
@raimannma raimannma merged commit 58f9a38 into master Feb 6, 2026
12 checks passed
@raimannma raimannma deleted the claude/deadlock-api-docs-schema-pj2LE branch February 6, 2026 11:08
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new tool for fetching Deadlock OpenAPI schemas and expands the agent’s built-in Deadlock API documentation so the assistant can answer endpoint/parameter questions from the live spec.

Changes:

  • Introduces DeadlockAPISchemaFetchTool to fetch OpenAPI JSON for the Game Data API or Assets API.
  • Expands DEADLOCK_API_INFO and updates the agent knowledge base with richer Deadlock API guidance/links.
  • Registers/cleans up the new tool in the tool registry and adds unit tests for the new behaviors.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
packages/tools/registry.py Registers the new schema-fetch tool with lazy init and closes it during registry cleanup.
packages/tools/openapi/deadlock_api.py Expands DEADLOCK_API_INFO, adds OPENAPI_SPEC_URLS, and implements DeadlockAPISchemaFetchTool.
packages/tools/openapi/openapi_test.py Adds new unit tests for DeadlockAPIInfoTool and DeadlockAPISchemaFetchTool.
packages/api/patreon_test.py Minor formatting adjustment in an existing test.
packages/ai_assistant/agent.py Updates the knowledge base with Deadlock API links and guidance on when to use each tool.
Comments suppressed due to low confidence (1)

packages/tools/openapi/deadlock_api.py:140

  • The DeadlockAPIInfoTool class docstring is now out of date: it says it only provides URLs for the main website/assets/data/GitHub, but DEADLOCK_API_INFO now includes an overview section plus Discord/Patreon links (and docs links). Updating the docstring will prevent misleading documentation for tool consumers.
    """Tool that returns information about the Deadlock API resources.

    Provides URLs and descriptions for the main website, assets API,
    data API, and GitHub repository.
    """

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +1472 to +1483
async def test_run_fetches_data_api_schema(self, schema_tool: DeadlockAPISchemaFetchTool) -> None:
"""Test fetching the data API schema."""
sample_spec = {
"openapi": "3.0.0",
"info": {"title": "Deadlock API", "version": "1.0.0"},
"paths": {"/v1/matches": {"get": {"summary": "Get matches"}}},
}

mock_response = MagicMock()
mock_response.json.return_value = sample_spec
mock_response.raise_for_status = MagicMock()

Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Schema fetching error handling currently has coverage for HTTP and network failures, but there isn’t a test for a successful HTTP response that contains invalid/non-JSON content (i.e., response.json() raising). After adding parse-error handling in DeadlockAPISchemaFetchTool, add a unit test asserting it raises OpenAPIConnectionError (and that the SSE end event reports a useful summary).

Copilot uses AI. Check for mistakes.
client = await self._get_client()
response = await client.get(spec_url)
response.raise_for_status()
return response.json()
Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DeadlockAPISchemaFetchTool._run doesn’t handle JSON decoding/parsing failures from response.json(). If the endpoint returns non-JSON (e.g., HTML error page with 200), this will raise a ValueError that bypasses the intended OpenAPIConnectionError path and results in inconsistent error reporting/retries. Consider catching JSON parse errors (or a broad Exception) around response.json() and re-raising as OpenAPIConnectionError with a helpful message (similar to OpenAPIToolGenerator.fetch_spec).

Suggested change
return response.json()
try:
return response.json()
except ValueError as e:
# Handle cases where the endpoint returns non-JSON (e.g., HTML error page with 2xx status)
raise OpenAPIConnectionError(
f"Failed to parse {api} API schema as JSON from {spec_url}"
) from e

Copilot uses AI. Check for mistakes.
Comment on lines +128 to +132
# OpenAPI spec URLs for schema fetching
OPENAPI_SPEC_URLS: dict[str, str] = {
"data": "https://api.deadlock-api.com/openapi.json",
"assets": "https://assets.deadlock-api.com/openapi.json",
}
Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DEADLOCK_API_INFO embeds the OpenAPI spec URLs as string literals while the same URLs are also defined in OPENAPI_SPEC_URLS. This duplication risks the two getting out of sync over time. Consider referencing OPENAPI_SPEC_URLS['data'] / OPENAPI_SPEC_URLS['assets'] when populating the openapi_spec fields (or building DEADLOCK_API_INFO from OPENAPI_SPEC_URLS) so there’s a single source of truth.

Copilot uses AI. Check for mistakes.
Comment on lines +238 to +250
async def _run(self, api: str) -> dict[str, Any]:
"""Fetch the OpenAPI schema for the specified API.

Args:
api: Which API to fetch the schema for ('data' or 'assets')

Returns:
The OpenAPI specification as a dictionary

Raises:
ValueError: If api is not 'data' or 'assets'
OpenAPIConnectionError: If the schema cannot be fetched
"""
Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method requires 2 positional arguments, whereas overridden BaseTool._run requires 1.

Suggested change
async def _run(self, api: str) -> dict[str, Any]:
"""Fetch the OpenAPI schema for the specified API.
Args:
api: Which API to fetch the schema for ('data' or 'assets')
Returns:
The OpenAPI specification as a dictionary
Raises:
ValueError: If api is not 'data' or 'assets'
OpenAPIConnectionError: If the schema cannot be fetched
"""
async def _run(self, *args: Any, **kwargs: Any) -> dict[str, Any]:
"""Fetch the OpenAPI schema for the specified API.
Args:
api: Which API to fetch the schema for ('data' or 'assets').
May be provided as the first positional argument or as a keyword
argument named 'api'.
Returns:
The OpenAPI specification as a dictionary
Raises:
ValueError: If api is not provided or is not 'data' or 'assets'
OpenAPIConnectionError: If the schema cannot be fetched
"""
api = args[0] if args else kwargs.get("api")
if api is None:
raise ValueError("Missing required 'api' argument. Must be one of: "
+ ", ".join(sorted(OPENAPI_SPEC_URLS)))

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants