Skip to content

Commit 17080a6

Browse files
committed
chore(ag-ui): improve content type name
Rename SSE_ACCEPT to SSE_CONTENT_TYPE for clarity and consistency.
1 parent 25aefc3 commit 17080a6

File tree

10 files changed

+35
-33
lines changed

10 files changed

+35
-33
lines changed

adapter_ag_ui/adapter_ag_ui/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77
from __future__ import annotations
88

99
from .adapter import AdapterAGUI
10-
from .consts import SSE_ACCEPT
10+
from .consts import SSE_CONTENT_TYPE
1111
from .deps import StateDeps
12+
from .protocols import StateHandler
1213

1314
__all__ = [
1415
'AdapterAGUI',
15-
'SSE_ACCEPT',
16+
'SSE_CONTENT_TYPE',
1617
'StateDeps',
18+
'StateHandler',
1719
]

adapter_ag_ui/adapter_ag_ui/adapter.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262

6363
from ._enums import Role
6464
from ._exceptions import NoMessagesError, RunError, UnexpectedToolCallError
65-
from .consts import SSE_ACCEPT
65+
from .consts import SSE_CONTENT_TYPE
6666
from .protocols import StateHandler
6767

6868
if TYPE_CHECKING:
@@ -123,7 +123,7 @@ class AdapterAGUI(Generic[AgentDepsT, OutputDataT]):
123123
from fastapi.responses import StreamingResponse
124124
from pydantic_ai import Agent
125125
126-
from adapter_ag_ui import SSE_ACCEPT, AdapterAGUI
126+
from adapter_ag_ui import SSE_CONTENT_TYPE, AdapterAGUI
127127
128128
if TYPE_CHECKING:
129129
from ag_ui.core import RunAgentInput
@@ -137,10 +137,10 @@ class AdapterAGUI(Generic[AgentDepsT, OutputDataT]):
137137
adapter = agent.to_ag_ui()
138138
139139
@app.post("/")
140-
async def root(input_data: RunAgentInput, accept: Annotated[str, Header()] = SSE_ACCEPT) -> StreamingResponse:
140+
async def root(input_data: RunAgentInput, accept: Annotated[str, Header()] = SSE_CONTENT_TYPE) -> StreamingResponse:
141141
return StreamingResponse(
142142
adapter.run(input_data, accept, deps=42),
143-
media_type="text/event-stream",
143+
media_type=SSE_CONTENT_TYPE,
144144
)
145145
146146
PydanticAI Tools which return AG-UI events will be sent to the client
@@ -149,11 +149,11 @@ async def root(input_data: RunAgentInput, accept: Annotated[str, Header()] = SSE
149149
150150
Examples:
151151
.. code-block:: python
152-
@agent.tool_plain
153-
def update_state(ctx: RunContext[StateDeps[int]]) -> StateSnapshotEvent:
152+
@agent.tool
153+
def update_state(ctx: RunContext[StateDeps[DocumentState]]) -> StateSnapshotEvent:
154154
return StateSnapshotEvent(
155155
type=EventType.STATE_SNAPSHOT,
156-
snapshot=state,
156+
snapshot=ctx.deps.state,
157157
)
158158
159159
@agent.tool_plain
@@ -184,7 +184,7 @@ def custom_events() -> list[CustomEvent]:
184184
async def run(
185185
self,
186186
run_input: RunAgentInput,
187-
accept: str = SSE_ACCEPT,
187+
accept: str = SSE_CONTENT_TYPE,
188188
*,
189189
output_type: OutputType[RunOutputDataT] | None = None,
190190
model: models.Model | models.KnownModelName | str | None = None,

adapter_ag_ui/adapter_ag_ui/consts.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44

55
from typing import Final
66

7-
SSE_ACCEPT: Final[str] = 'text/event-stream'
8-
"""Accept header value for Server-Sent Events (SSE)."""
7+
SSE_CONTENT_TYPE: Final[str] = 'text/event-stream'
8+
"""Content type header value for Server-Sent Events (SSE)."""

examples/adapter_ag_ui_examples/api/agentic_chat.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from typing import TYPE_CHECKING, Annotated
77
from zoneinfo import ZoneInfo
88

9-
from adapter_ag_ui.consts import SSE_ACCEPT
9+
from adapter_ag_ui.consts import SSE_CONTENT_TYPE
1010
from ag_ui.core import RunAgentInput
1111
from fastapi import APIRouter, Header
1212
from fastapi.responses import StreamingResponse
@@ -37,7 +37,7 @@ async def current_time(timezone: str = 'UTC') -> str:
3737

3838
@router.post('')
3939
async def handler(
40-
input_data: RunAgentInput, accept: Annotated[str, Header()] = SSE_ACCEPT
40+
input_data: RunAgentInput, accept: Annotated[str, Header()] = SSE_CONTENT_TYPE
4141
) -> StreamingResponse:
4242
"""Endpoint to handle AG-UI protocol requests and stream responses.
4343
@@ -50,5 +50,5 @@ async def handler(
5050
"""
5151
return StreamingResponse(
5252
agui.adapter.run(input_data, accept),
53-
media_type=SSE_ACCEPT,
53+
media_type=SSE_CONTENT_TYPE,
5454
)

examples/adapter_ag_ui_examples/api/agentic_generative_ui.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from enum import StrEnum
44
from typing import Annotated, Any, Literal
55

6-
from adapter_ag_ui.consts import SSE_ACCEPT
6+
from adapter_ag_ui.consts import SSE_CONTENT_TYPE
77
from ag_ui.core import EventType, RunAgentInput, StateDeltaEvent, StateSnapshotEvent
88
from fastapi import APIRouter, Header
99
from fastapi.responses import StreamingResponse
@@ -122,7 +122,7 @@ def update_plan_step(
122122

123123
@router.post('')
124124
async def handler(
125-
input_data: RunAgentInput, accept: Annotated[str, Header()] = SSE_ACCEPT
125+
input_data: RunAgentInput, accept: Annotated[str, Header()] = SSE_CONTENT_TYPE
126126
) -> StreamingResponse:
127127
"""Endpoint to handle AG-UI protocol requests and stream responses.
128128
@@ -135,5 +135,5 @@ async def handler(
135135
"""
136136
return StreamingResponse(
137137
agui.adapter.run(input_data, accept),
138-
media_type=SSE_ACCEPT,
138+
media_type=SSE_CONTENT_TYPE,
139139
)

examples/adapter_ag_ui_examples/api/human_in_the_loop.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from typing import TYPE_CHECKING, Annotated
99

10-
from adapter_ag_ui.consts import SSE_ACCEPT
10+
from adapter_ag_ui.consts import SSE_CONTENT_TYPE
1111
from ag_ui.core import RunAgentInput
1212
from fastapi import APIRouter, Header
1313
from fastapi.responses import StreamingResponse
@@ -31,7 +31,7 @@
3131

3232
@router.post('')
3333
async def handler(
34-
input_data: RunAgentInput, accept: Annotated[str, Header()] = SSE_ACCEPT
34+
input_data: RunAgentInput, accept: Annotated[str, Header()] = SSE_CONTENT_TYPE
3535
) -> StreamingResponse:
3636
"""Endpoint to handle AG-UI protocol requests and stream responses.
3737
@@ -44,5 +44,5 @@ async def handler(
4444
"""
4545
return StreamingResponse(
4646
agui.adapter.run(input_data, accept),
47-
media_type=SSE_ACCEPT,
47+
media_type=SSE_CONTENT_TYPE,
4848
)

examples/adapter_ag_ui_examples/api/predictive_state_updates.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import logging
66
from typing import TYPE_CHECKING, Annotated
77

8-
from adapter_ag_ui.consts import SSE_ACCEPT
8+
from adapter_ag_ui.consts import SSE_CONTENT_TYPE
99
from adapter_ag_ui.deps import StateDeps
1010
from ag_ui.core import CustomEvent, EventType, RunAgentInput
1111
from fastapi import APIRouter, Header
@@ -90,7 +90,7 @@ def story_instructions(ctx: RunContext[StateDeps[DocumentState]]) -> str:
9090

9191
@router.post('')
9292
async def handler(
93-
input_data: RunAgentInput, accept: Annotated[str, Header()] = SSE_ACCEPT
93+
input_data: RunAgentInput, accept: Annotated[str, Header()] = SSE_CONTENT_TYPE
9494
) -> StreamingResponse:
9595
"""Endpoint to handle AG-UI protocol requests and stream responses.
9696
@@ -103,5 +103,5 @@ async def handler(
103103
"""
104104
return StreamingResponse(
105105
agui.adapter.run(input_data, accept, deps=StateDeps(state_type=DocumentState)),
106-
media_type=SSE_ACCEPT,
106+
media_type=SSE_CONTENT_TYPE,
107107
)

examples/adapter_ag_ui_examples/api/shared_state.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from enum import StrEnum
88
from typing import TYPE_CHECKING, Annotated
99

10-
from adapter_ag_ui.consts import SSE_ACCEPT
10+
from adapter_ag_ui.consts import SSE_CONTENT_TYPE
1111
from adapter_ag_ui.deps import StateDeps
1212
from ag_ui.core import EventType, RunAgentInput, StateSnapshotEvent
1313
from fastapi import APIRouter, Header
@@ -141,7 +141,7 @@ def recipe_instructions(ctx: RunContext[StateDeps[RecipeSnapshot]]) -> str:
141141

142142
@router.post('')
143143
async def handler(
144-
input_data: RunAgentInput, accept: Annotated[str, Header()] = SSE_ACCEPT
144+
input_data: RunAgentInput, accept: Annotated[str, Header()] = SSE_CONTENT_TYPE
145145
) -> StreamingResponse:
146146
"""Endpoint to handle AG-UI protocol requests and stream responses.
147147
@@ -154,5 +154,5 @@ async def handler(
154154
"""
155155
return StreamingResponse(
156156
agui.adapter.run(input_data, accept, deps=StateDeps(state_type=RecipeSnapshot)),
157-
media_type=SSE_ACCEPT,
157+
media_type=SSE_CONTENT_TYPE,
158158
)

examples/adapter_ag_ui_examples/api/tool_based_generative_ui.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from typing import TYPE_CHECKING, Annotated
99

10-
from adapter_ag_ui.consts import SSE_ACCEPT
10+
from adapter_ag_ui.consts import SSE_CONTENT_TYPE
1111
from ag_ui.core import RunAgentInput
1212
from fastapi import APIRouter, Header
1313
from fastapi.responses import StreamingResponse
@@ -24,7 +24,7 @@
2424

2525
@router.post('')
2626
async def handler(
27-
input_data: RunAgentInput, accept: Annotated[str, Header()] = SSE_ACCEPT
27+
input_data: RunAgentInput, accept: Annotated[str, Header()] = SSE_CONTENT_TYPE
2828
) -> StreamingResponse:
2929
"""Endpoint to handle AG-UI protocol requests and stream responses.
3030
@@ -37,5 +37,5 @@ async def handler(
3737
"""
3838
return StreamingResponse(
3939
agui.adapter.run(input_data, accept),
40-
media_type=SSE_ACCEPT,
40+
media_type=SSE_CONTENT_TYPE,
4141
)

examples/adapter_ag_ui_examples/basic.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from typing import TYPE_CHECKING, Annotated
66

77
from adapter_ag_ui.adapter import AdapterAGUI
8-
from adapter_ag_ui.consts import SSE_ACCEPT
8+
from adapter_ag_ui.consts import SSE_CONTENT_TYPE
99
from fastapi import FastAPI, Header
1010
from fastapi.responses import StreamingResponse
1111

@@ -25,7 +25,7 @@
2525

2626
@app.post('/agent')
2727
async def handler(
28-
input_data: RunAgentInput, accept: Annotated[str, Header()] = SSE_ACCEPT
28+
input_data: RunAgentInput, accept: Annotated[str, Header()] = SSE_CONTENT_TYPE
2929
) -> StreamingResponse:
3030
"""Endpoint to handle AG-UI protocol requests and stream responses.
3131
@@ -38,7 +38,7 @@ async def handler(
3838
"""
3939
return StreamingResponse(
4040
adapter.run(input_data, accept),
41-
media_type='text/event-stream',
41+
media_type=SSE_CONTENT_TYPE,
4242
)
4343

4444

0 commit comments

Comments
 (0)