Optimize broker concurrency and add rate limiting middleware#23
Merged
Optimize broker concurrency and add rate limiting middleware#23
Conversation
… A2A endpoint, rate limiting, CI tests - #7: Batch independent DB queries in broker invoke_agent() with asyncio.gather() to reduce sequential round trips (config + agent + conversation fetched concurrently) - #8: Replace polling-based Redis semaphore with pub/sub notifications for near-instant slot acquisition, with fallback to polling if pub/sub fails - #15: Add A2A-compatible AgentCard endpoint at /.well-known/agent.json for agent-to-agent discovery - #11: Add Redis-backed rate limiting middleware with Retry-After headers and graceful degradation when Redis is unavailable - #17: Re-enable CI test job (remove if:false gate), add conftest to skip live integration tests, add smoke tests for CI All changes are internal optimizations or additive endpoints — no breaking changes to the public API surface or intuno-sdk compatibility. https://claude.ai/code/session_015zTWwVFtUWeN5ameM6teEa
Collaborator
Author
- Use pipeline expire instead of conditional TTL check to prevent key living forever if process crashes between INCR and EXPIRE - Fix docstring: "sliding window" → "fixed-window" to match implementation - Replace hardcoded agent card URL with settings.BASE_URL for staging/dev - Add BASE_URL setting (defaults to https://api.intuno.ai) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR improves performance and reliability of the agent broker by batching independent async lookups, adds Redis-backed rate limiting middleware, enhances the concurrency limiter with pub/sub notifications, and adds smoke tests for CI.
Key Changes
Broker Performance Optimization (
src/services/broker.py)invoke_agent()to useasyncio.gather()for independent database/repository calls (config, agent, conversation) instead of sequential awaits, reducing latencyconv_idis provided, avoiding unnecessary queriesRate Limiting Middleware (
src/core/rate_limit.py- new)RateLimitMiddlewareusing Redis fixed-window counters per client (by user ID or IP)Retry-Afterand rate limit headers when limit exceededRATE_LIMIT_ENABLEDandRATE_LIMIT_REQUESTS_PER_MINUTEsettingsConcurrency Limiter Enhancement (
src/workflow/utils/concurrency.py)RedisSemaphorenow uses Redis pub/sub to notify waiters when slots are released instead of pollingAPI Metadata Endpoints (
src/main.py)/.well-known/agent.jsonendpoint for A2A (agent-to-agent) discovery with AgentCard format/.well-known/mcp/server-card.jsonfor readabilityRateLimitMiddlewareto middleware stackSettings (
src/core/settings.py)RATE_LIMIT_ENABLED(default: True) andRATE_LIMIT_REQUESTS_PER_MINUTEconfiguration optionsTesting (
tests/test_smoke.py- new,tests/conftest.py- new)-m "not integration"CI (
github/workflows/ci.yml)Implementation Details
https://claude.ai/code/session_015zTWwVFtUWeN5ameM6teEa