Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
165 commits
Select commit Hold shift + click to select a range
173085d
feat: initial implementation of ADK middleware for AG-UI Protocol
mefogle Jul 4, 2025
b9c2977
feat: major refactoring and enhancements to ADK middleware
mefogle Jul 5, 2025
40ef583
chore: update all python3 references to python for consistency
mefogle Jul 5, 2025
04d4cda
feat: add default app_name behavior using agent name from registry
mefogle Jul 5, 2025
6b7108a
Merge branch 'ag-ui-protocol:main' into adk-middleware
contextablemark Jul 5, 2025
865f7c7
refactor: move all tests to tests/ directory for better organization
mefogle Jul 5, 2025
86094a4
fix: update changelog for test reorganization
mefogle Jul 5, 2025
5f73078
Updating requirements.txt.
mefogle Jul 5, 2025
d81d82b
Added version for asyncio.
mefogle Jul 5, 2025
11aca27
docs: update README to reflect current implementation status
mefogle Jul 5, 2025
aa04096
feat: implement full pytest compatibility for test suite
mefogle Jul 5, 2025
2683a30
fix: remove accidentally committed ADK_Middleware directory and CLAUD…
mefogle Jul 5, 2025
a1ebaa3
docs: update README feature status to reflect current implementation
mefogle Jul 5, 2025
555a3e3
refactor: separate dev dependencies and fix README examples
mefogle Jul 6, 2025
589303c
feat: add automatic session memory and refactor session management
mefogle Jul 6, 2025
eebd544
refactor: simplify logging system to use standard Python logging
mefogle Jul 6, 2025
51b663f
fix adk_middleware python module and added adk-middleware demo in doj…
syedfakher27 Jul 6, 2025
afbaf00
import change
syedfakher27 Jul 7, 2025
246bee6
venv in git ignore
syedfakher27 Jul 7, 2025
e41471d
fixing test adk_middleware imports
syedfakher27 Jul 7, 2025
ad407cb
all test cases fixed
syedfakher27 Jul 7, 2025
41dd2c1
Merge pull request #1 from syedfakher27/adk-middleware
contextablemark Jul 7, 2025
be845b3
Update documentation and fix session attribute name
mefogle Jul 7, 2025
5c89c7f
Fix test failures: Update attribute name references
mefogle Jul 7, 2025
443ea4d
Fix test failures: Update attribute name references
mefogle Jul 7, 2025
e14f0b6
Fix session manager last_update_time timestamp bug
mefogle Jul 7, 2025
d9d712d
Merge adk-middleware branch to get session manager timestamp fix
mefogle Jul 7, 2025
0e40baa
Add complete bidirectional tool support for ADK middleware
mefogle Jul 7, 2025
64b93f0
Merge pull request #2 from Contextable/feature/tool-support
contextablemark Jul 7, 2025
c053ed6
added tool based generative ui demo
syedfakher27 Jul 8, 2025
f0dea33
print remove
syedfakher27 Jul 8, 2025
e2d06f0
fix tool wrapper test case
syedfakher27 Jul 8, 2025
4b8d173
fix test_endpoint
syedfakher27 Jul 8, 2025
9429aac
test cases fixed
syedfakher27 Jul 8, 2025
05c847e
Update typescript-sdk/integrations/adk-middleware/src/adk_middleware/…
contextablemark Jul 8, 2025
e1fa842
Merge pull request #3 from syedfakher27/adk-middleware
contextablemark Jul 8, 2025
2eb3f28
Release 0.3.2: Hybrid tool execution model with per-tool configuration
mefogle Jul 8, 2025
90deb89
Merge pull request #4 from Contextable/feature/hybrid-tool-execution
contextablemark Jul 8, 2025
5c59fc3
Comprehensive unit test coverage improvements for low-coverage modules
mefogle Jul 8, 2025
eb9d998
Update changelog for improved test coverage
mefogle Jul 8, 2025
64f6a82
Merge pull request #5 from Contextable/improve-unit-test-coverage
contextablemark Jul 8, 2025
eeb47f1
tool submission changes for ADK middleware
syedfakher27 Jul 9, 2025
aae9227
refactor: align tool behavior with ADK standards and fix test coverage
mefogle Jul 9, 2025
0765e9c
Complete ADK middleware test suite fixes - achieve 100% test pass rate
mefogle Jul 10, 2025
4ab8703
Merge pull request #7 from Contextable/refactor-adk-tool-implementation
contextablemark Jul 10, 2025
befc12c
feat: simplify to all-long-running tool architecture with critical bu…
mefogle Jul 11, 2025
517593d
prompt change
syedfakher27 Jul 11, 2025
801bcd7
feat: merge adk-middleware improvements into all-long-running archite…
mefogle Jul 11, 2025
88b1a32
Merge pull request #8 from Contextable/feature/all-long-running-tools…
contextablemark Jul 11, 2025
4a49c62
Merge branch 'ag-ui-protocol:main' into adk-middleware
contextablemark Jul 11, 2025
0f7e780
Merge branch 'ag-ui-protocol:main' into adk-middleware
contextablemark Jul 12, 2025
520e442
feat: add GitHub Actions CI workflow for ADK middleware
mefogle Jul 13, 2025
e74ffc2
Merge pull request #15 from Contextable/feature/ci-integration
contextablemark Jul 13, 2025
e2bb46b
feat: fix memory persistence and tool ID mapping (v0.4.1)
mefogle Jul 13, 2025
9e39785
Merge pull request #16 from Contextable/feature/memory-bank
contextablemark Jul 13, 2025
077989d
Adding files that were left out of PR #16 and removing unusable workf…
mefogle Jul 13, 2025
dacd7cb
Merge pull request #17 from Contextable/feature/memory-bank
contextablemark Jul 13, 2025
b5b29d5
fix: update test to check debug logging instead of info
mefogle Jul 13, 2025
64ac064
Merge pull request #18 from Contextable/fix/endpoint-logging-test
contextablemark Jul 13, 2025
7cb6b36
shared state demo for dojo app
syedfakher27 Jul 13, 2025
d332319
shared_state_agent added
syedfakher27 Jul 13, 2025
3f464a7
Merge remote-tracking branch 'upstream/adk-middleware' into adk-middl…
syedfakher27 Jul 13, 2025
a956e78
fix: resolve EventType.STATE_DELTA patch error (issue #20)
mefogle Jul 13, 2025
0a2212d
Merge pull request #21 from Contextable/fix/issue-20-state-delta-patc…
contextablemark Jul 13, 2025
58b45bd
feat: add SystemMessage support and fix tool result race condition
mefogle Jul 14, 2025
5975788
Merge pull request #23 from Contextable/feature/system-message-suppor…
contextablemark Jul 14, 2025
5f61634
dojo app backend command added
syedfakher27 Jul 14, 2025
0f00725
session update comments added
syedfakher27 Jul 14, 2025
a37a7fd
Merge remote-tracking branch 'upstream/adk-middleware' into adk-middl…
syedfakher27 Jul 14, 2025
a45eff2
_create_state_delta_event added back
syedfakher27 Jul 14, 2025
365efe0
added memory back again
syedfakher27 Jul 14, 2025
0f35666
simple instructions
syedfakher27 Jul 14, 2025
2f2449c
twice generative AI and HITL fixed
syedfakher27 Jul 14, 2025
e39cd4e
unit test updated for _translate_function_calls
syedfakher27 Jul 14, 2025
0d65159
Update typescript-sdk/integrations/adk-middleware/examples/shared_sta…
syedfakher27 Jul 15, 2025
3e211d0
Update typescript-sdk/integrations/adk-middleware/tests/test_event_tr…
syedfakher27 Jul 15, 2025
74b7f40
Update typescript-sdk/integrations/adk-middleware/examples/fastapi_se…
syedfakher27 Jul 15, 2025
bf4dc54
Update typescript-sdk/integrations/adk-middleware/examples/shared_sta…
syedfakher27 Jul 15, 2025
c7d5e54
Update typescript-sdk/integrations/adk-middleware/examples/shared_sta…
syedfakher27 Jul 15, 2025
ef563f9
Update typescript-sdk/integrations/adk-middleware/src/adk_middleware/…
syedfakher27 Jul 15, 2025
378c642
Update typescript-sdk/integrations/adk-middleware/examples/shared_sta…
syedfakher27 Jul 15, 2025
9339691
Update typescript-sdk/integrations/adk-middleware/examples/fastapi_se…
syedfakher27 Jul 15, 2025
e47627c
test cases for session management added
syedfakher27 Jul 15, 2025
25d3f69
Update typescript-sdk/integrations/adk-middleware/examples/shared_sta…
contextablemark Jul 15, 2025
edc9d25
Update typescript-sdk/integrations/adk-middleware/examples/shared_sta…
contextablemark Jul 15, 2025
1108526
Update typescript-sdk/integrations/adk-middleware/examples/shared_sta…
contextablemark Jul 15, 2025
27b8730
Merge pull request #19 from syedfakher27/adk-middleware
syedfakher27 Jul 15, 2025
aec1385
adk_shared_state_agent fixed
syedfakher27 Jul 15, 2025
4df0a2c
fix: resolve flaky test_bulk_update_user_state_mixed_results
mefogle Jul 17, 2025
81b6c92
Merge pull request #27 from Contextable/fix/flaky-session-test
contextablemark Jul 17, 2025
17b7da5
Merge pull request #26 from syedfakher27/adk-middleware
contextablemark Jul 17, 2025
8d36475
Merge branch 'ag-ui-protocol:main' into adk-middleware
contextablemark Jul 19, 2025
bae3bd7
snapshot error fixed
syedfakher27 Jul 20, 2025
1790c4b
function response
syedfakher27 Jul 20, 2025
35047b5
Merge pull request #29 from syedfakher27/adk-middleware
syedfakher27 Jul 20, 2025
24f41a1
Update agent.py
syedfakher27 Jul 21, 2025
a1410c6
Merge remote-tracking branch 'upstream/adk-middleware' into adk-middl…
syedfakher27 Jul 21, 2025
1ff5971
Merge pull request #31 from syedfakher27/adk-middleware
contextablemark Jul 22, 2025
47c8dc3
refactor: use SessionManager methods for pending tool call state mana…
mefogle Jul 24, 2025
ac914b9
removing the print statements
syedfakher27 Jul 26, 2025
3f4342b
long running tool backend handling
syedfakher27 Jul 26, 2025
62da096
update the instruction for the chat demo
syedfakher27 Jul 26, 2025
878cf54
predictive state demo added
syedfakher27 Jul 26, 2025
5e2ec4b
Update typescript-sdk/integrations/adk-middleware/examples/fastapi_se…
syedfakher27 Jul 26, 2025
edd8897
fix: use SessionManager methods for pending tool call state management
mefogle Jul 26, 2025
6d7d558
Merge pull request #34 from Contextable/issue-25-fix
contextablemark Jul 26, 2025
94cf5da
Merge remote-tracking branch 'upstream/adk-middleware' into adk-middl…
syedfakher27 Jul 26, 2025
ac2830a
backend tool pending issue fixed
syedfakher27 Jul 26, 2025
34be480
Update Changelog.md
syedfakher27 Jul 26, 2025
cf9d1c0
TestEventTranslatorComprehensive tests fixed
syedfakher27 Jul 26, 2025
b9b85e1
recipe prompt change
syedfakher27 Jul 29, 2025
626d9ba
model updated for human in loop
syedfakher27 Jul 30, 2025
5243567
Initial documentation changes
contextablemark Aug 2, 2025
20bce0b
Merge branch 'main' into adk-middleware
contextablemark Aug 2, 2025
1f9da91
feat: eliminate AgentRegistry and implement direct agent embedding
mefogle Aug 2, 2025
f45b00e
docs: update documentation to remove AgentRegistry references
mefogle Aug 2, 2025
14bab93
stopping condition added
syedfakher27 Aug 5, 2025
527c112
feat: make session_service configurable in ADKAgent constructor
mefogle Aug 5, 2025
8e13a52
print statement removed
syedfakher27 Aug 5, 2025
d5ddc14
Merge pull request #33 from syedfakher27/adk-middleware
contextablemark Aug 5, 2025
c1e5b53
Merge branch 'ag-ui-protocol:main' into adk-middleware
contextablemark Aug 5, 2025
f897d0b
Merge branch 'adk-middleware' into issue-24-cleanup-agent-registration
contextablemark Aug 5, 2025
0330453
Removing registry entries and redundant constructor.
mefogle Aug 5, 2025
82b4395
Added support for agentFilesMapper.
mefogle Aug 5, 2025
ceec7e6
Merge branch 'ag-ui-protocol:main' into adk-middleware
contextablemark Aug 5, 2025
849ca93
Merge branch 'adk-middleware' into issue-24-cleanup-agent-registration
mefogle Aug 5, 2025
848b465
Fix ADKAgent test suite for new architecture
mefogle Aug 5, 2025
5d16bb1
Merge pull request #36 from Contextable/issue-24-cleanup-agent-regist…
contextablemark Aug 5, 2025
e821ba4
Added in updated file content.
mefogle Aug 5, 2025
20d8971
Merge pull request #40 from Contextable/issue-24-cleanup-agent-regist…
contextablemark Aug 5, 2025
c4c175e
Add e2e tests for ADK middleware agentic chat
mefogle Aug 6, 2025
629cfe0
Merge pull request #41 from Contextable/feature/adk-e2e-tests
contextablemark Aug 6, 2025
bea6ef9
Merge branch 'ag-ui-protocol:main' into adk-middleware
contextablemark Aug 6, 2025
2aec7e0
feat: Make ADK middleware base URL configurable via environment variable
mefogle Aug 7, 2025
cedc747
Merge pull request #43 from Contextable/railway
contextablemark Aug 7, 2025
9924908
feat: Upgrade Google ADK dependency to 1.9.0
mefogle Aug 7, 2025
e04c063
Merge pull request #44 from Contextable/adk-upgrade
contextablemark Aug 7, 2025
5e54f15
Merge branch 'adk-middleware' into issue-35
contextablemark Aug 7, 2025
9a1b9ce
docs: Extensive documentation restructuring for improved organization
mefogle Aug 7, 2025
3313c27
Merge pull request #45 from Contextable/issue-35
contextablemark Aug 7, 2025
97996a2
Merge branch 'ag-ui-protocol:main' into adk-middleware
contextablemark Aug 7, 2025
41660e5
fix: support instructions provider for agents
evgeny-l Aug 8, 2025
0c1fd6d
fix: support of before_agent_callback in case of a direct content res…
evgeny-l Aug 8, 2025
70aa99e
Merge branch 'ag-ui-protocol:main' into adk-middleware
contextablemark Aug 11, 2025
b7063c6
Added aiohttp dependency.
mefogle Aug 12, 2025
4b3207c
Merge pull request #50 from Contextable/aiohttp_issue
contextablemark Aug 12, 2025
b7aca0f
Merge branch 'ag-ui-protocol:main' into adk-middleware
contextablemark Aug 14, 2025
4ce24b9
- General cleanup
mefogle Aug 14, 2025
7abe5b9
Merge pull request #52 from Contextable/general-cleanup
contextablemark Aug 14, 2025
27a9925
Update typescript-sdk/integrations/adk-middleware/src/adk_middleware/…
evgeny-l Aug 14, 2025
9d418d3
Update typescript-sdk/integrations/adk-middleware/tests/test_text_eve…
evgeny-l Aug 14, 2025
60bd9a1
fix: support of before_agent_callback in case of a direct content res…
evgeny-l Aug 14, 2025
4255743
fix: support instructions provider for agents - handle sync cases and…
evgeny-l Aug 14, 2025
446f2e9
Merge pull request #49 from evgeny-l/adk-middleware-before-agent-call…
contextablemark Aug 14, 2025
f20257f
Merge pull request #48 from evgeny-l/adk-middleware-instructions-prov…
contextablemark Aug 14, 2025
c1596c9
Merge branch 'ag-ui-protocol:main' into adk-middleware
contextablemark Aug 16, 2025
aaae5da
fix: update tests to match new logging levels from PR #49
contextablemark Aug 16, 2025
0835b5b
Merge pull request #53 from Contextable/fix/test-logging-levels
contextablemark Aug 16, 2025
3b84edd
fix: change misleading 'Session not found' warnings to debug messages
contextablemark Aug 19, 2025
856fac3
Merge pull request #54 from Contextable/fix/session-not-found-warning
contextablemark Aug 19, 2025
e4ffff6
Merge branch 'ag-ui-protocol:main' into adk-middleware
contextablemark Aug 24, 2025
00f3b5f
Merge branch 'ag-ui-protocol:main' into adk-middleware
contextablemark Aug 27, 2025
6703c09
Merge branch 'ag-ui-protocol:main' into adk-middleware
contextablemark Aug 29, 2025
bff1b59
Merge branch 'ag-ui-protocol:main' into adk-middleware
contextablemark Sep 3, 2025
3d54ae7
Merge branch 'ag-ui-protocol:main' into adk-middleware
contextablemark Sep 9, 2025
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
**/.claude/settings.local.json
.vscode/
.idea/
1 change: 1 addition & 0 deletions typescript-sdk/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,5 @@ packages/proto/src/generated
**/**/.langgraph_api

# Python
venv
__pycache__/
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { test, expect } from '@playwright/test';

test('responds to user message', async ({ page }) => {
await page.goto('http://localhost:9999/adk-middleware/feature/agentic_chat');

// 1. Wait for the page to be fully ready by ensuring the initial message is visible.
await expect(page.getByText("Hi, I'm an agent. Want to chat?")).toBeVisible({ timeout: 10000 });

// 2. Interact with the page to send the message.
const textarea = page.getByPlaceholder('Type a message...');
await textarea.fill('How many sides are in a square? Please answer in one word. Do not use any punctuation, just the number in word form.');
await page.keyboard.press('Enter');

// 3. Assert the final state with a generous timeout.
// This is the most important part. We target the *second* assistant message
// and wait for it to contain the text "Four". Playwright handles all the waiting.
const finalResponse = page.locator('.copilotKitMessage.copilotKitAssistantMessage').nth(1);
await expect(finalResponse).toContainText(/four/i, { timeout: 15000 });

// 4. (Optional) For added certainty, verify the total message count.
// This confirms there are exactly 3 messages: greeting, user query, and agent response.
await expect(page.locator('.copilotKitMessage')).toHaveCount(3);
});
6 changes: 6 additions & 0 deletions typescript-sdk/apps/dojo/scripts/generate-content-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,12 @@ const agentFilesMapper: Record<string, (agentKeys: string[]) => Record<string, s
...acc,
[agentId]: [path.join(__dirname, integrationsFolderPath, `/crewai/python/ag_ui_crewai/examples/${agentId}.py`)]
}), {})
},
'adk-middleware': (agentKeys: string[]) => {
return agentKeys.reduce((acc, agentId) => ({
...acc,
[agentId]: [path.join(__dirname, integrationsFolderPath, `/adk-middleware/examples/fastapi_server.py`)]
}), {})
}
}

Expand Down
12 changes: 12 additions & 0 deletions typescript-sdk/apps/dojo/src/agents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,18 @@ export const agentsIntegrations: AgentIntegrationConfig[] = [
};
},
},
{
id: "adk-middleware",
agents: async () => {
return {
agentic_chat: new ServerStarterAgent({ url: `${envVars.adkMiddlewareUrl}/chat` }),
tool_based_generative_ui: new ServerStarterAgent({ url: `${envVars.adkMiddlewareUrl}/adk-tool-based-generative-ui` }),
human_in_the_loop: new ServerStarterAgent({ url: `${envVars.adkMiddlewareUrl}/adk-human-in-loop-agent` }),
shared_state: new ServerStarterAgent({ url: `${envVars.adkMiddlewareUrl}/adk-shared-state-agent` }),
predictive_state_updates: new ServerStarterAgent({ url: `${envVars.adkMiddlewareUrl}/adk-predictive-state-agent` }),
};
},
},
{
id: "server-starter-all-features",
agents: async () => {
Expand Down
2 changes: 2 additions & 0 deletions typescript-sdk/apps/dojo/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ type envVars = {
llamaIndexUrl: string;
crewAiUrl: string;
pydanticAIUrl: string;
adkMiddlewareUrl: string;
customDomainTitle: Record<string, string>;
}

Expand All @@ -32,6 +33,7 @@ export default function getEnvVars(): envVars {
llamaIndexUrl: process.env.LLAMA_INDEX_URL || 'http://localhost:9000',
crewAiUrl: process.env.CREW_AI_URL || 'http://localhost:9002',
pydanticAIUrl: process.env.PYDANTIC_AI_URL || 'http://localhost:9000',
adkMiddlewareUrl: process.env.ADK_MIDDLEWARE_URL || 'http://localhost:8000',
customDomainTitle: customDomainTitle,
}
}
130 changes: 130 additions & 0 deletions typescript-sdk/apps/dojo/src/files.json

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions typescript-sdk/apps/dojo/src/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ export const menuIntegrations: MenuIntegrationConfig[] = [
name: "Server Starter",
features: ["agentic_chat"],
},
{
id: "adk-middleware",
name: "ADK Middleware",
features: ["agentic_chat","tool_based_generative_ui","human_in_the_loop","shared_state","predictive_state_updates"],
},
{
id: "server-starter-all-features",
name: "Server Starter (All Features)",
Expand Down
86 changes: 86 additions & 0 deletions typescript-sdk/integrations/adk-middleware/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Python
__pycache__/
*.py[cod]
*$py.class
*.so
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# Virtual Environment
venv/
env/
ENV/
env.bak/
venv.bak/
test_env/

# IDE
.vscode/
.idea/
*.swp
*.swo
*~
.project
.pydevproject

# Testing
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# OS
.DS_Store
Thumbs.db

# Development scripts and temp files
set_pythonpath.sh
simple_test_server.py

# External project directories

# Local documentation
CLAUDE.md
128 changes: 128 additions & 0 deletions typescript-sdk/integrations/adk-middleware/ARCHITECTURE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
# ADK Middleware Architecture

This document describes the architecture and design of the ADK Middleware that bridges Google ADK agents with the AG-UI Protocol.

## High-Level Architecture

```
AG-UI Protocol ADK Middleware Google ADK
│ │ │
RunAgentInput ──────> ADKAgent.run() ──────> Runner.run_async()
│ │ │
│ EventTranslator │
│ │ │
BaseEvent[] <──────── translate events <──────── Event[]
```

## Core Components

### ADKAgent (`adk_agent.py`)
The main orchestrator that:
- Manages agent lifecycle and session state
- Handles the bridge between AG-UI Protocol and ADK
- Coordinates tool execution through proxy tools
- Implements direct agent embedding pattern

### EventTranslator (`event_translator.py`)
Converts between event formats:
- ADK events → AG-UI protocol events (16 standard event types)
- Maintains proper message boundaries
- Handles streaming text content
- Per-session instances for thread safety

### SessionManager (`session_manager.py`)
Singleton pattern for centralized session control:
- Automatic session cleanup with configurable timeouts
- Session isolation per user
- Memory service integration for session persistence
- Resource management and limits

### ExecutionState (`execution_state.py`)
Tracks background ADK executions:
- Manages asyncio tasks running ADK agents
- Event queue for streaming results
- Execution timing and completion tracking
- Tool call state management

### ClientProxyTool (`client_proxy_tool.py`)
Individual tool proxy implementation:
- Wraps AG-UI tools for ADK compatibility
- Emits tool events to client
- Currently all tools are long-running
- Integrates with ADK's tool system

### ClientProxyToolset (`client_proxy_toolset.py`)
Manages collections of proxy tools:
- Dynamic toolset creation per request
- Fresh tool instances for each execution
- Combines client and backend tools

## Event Flow

1. **Client Request**: AG-UI Protocol `RunAgentInput` received
2. **Session Resolution**: SessionManager finds or creates session
3. **Agent Execution**: ADK Runner executes agent with context
4. **Tool Handling**: ClientProxyTools emit events for client-side execution
5. **Event Translation**: ADK events converted to AG-UI events
6. **Streaming Response**: Events streamed back via SSE or other transport

## Key Design Patterns

### Direct Agent Embedding
```python
# Agents are directly embedded in ADKAgent instances
agent = ADKAgent(
adk_agent=my_adk_agent, # Direct reference
app_name="my_app",
user_id="user123"
)
```

### Service Dependency Injection
The middleware uses dependency injection for ADK services:
- Session service (default: InMemorySessionService)
- Memory service (optional, enables session persistence)
- Artifact service (default: InMemoryArtifactService)
- Credential service (default: InMemoryCredentialService)

### Tool Proxy Pattern
All client-supplied tools are wrapped as long-running ADK tools:
- Emit events for client-side execution
- Can be combined with backend tools
- Unified tool handling interface

### Session Lifecycle
1. Session created on first request
2. Maintained across multiple runs
3. Automatic cleanup after timeout
4. Optional persistence to memory service

## Thread Safety

- Per-session EventTranslator instances
- Singleton SessionManager with proper locking
- Isolated execution states per thread
- Thread-safe event queues

## Error Handling

- RunErrorEvent for various failure scenarios
- Proper async exception handling
- Resource cleanup on errors
- Timeout management at multiple levels

## Performance Considerations

- Async/await throughout for non-blocking operations
- Event streaming for real-time responses
- Configurable concurrent execution limits
- Automatic stale execution cleanup
- Efficient event queue management

## Future Enhancements

- Additional tool execution modes
- Enhanced state synchronization
- More sophisticated error recovery
- Performance optimizations
- Extended protocol support
Loading