Skip to content
Closed
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
186 changes: 185 additions & 1 deletion src/llama_stack_client/resources/agents/turn.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
)
from ..._streaming import Stream, AsyncStream
from ..._base_client import make_request_options
from ...types.agents import turn_create_params
from ...types.agents import turn_create_params, turn_continue_params
from ...types.agents.turn import Turn
from ...types.agents.agent_turn_response_stream_chunk import AgentTurnResponseStreamChunk

Expand Down Expand Up @@ -225,6 +225,92 @@ def retrieve(
cast_to=Turn,
)

@overload
def continue_(
self,
turn_id: str,
*,
agent_id: str,
session_id: str,
new_messages: Iterable[turn_continue_params.NewMessage],
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> Turn:
"""
Args:
extra_headers: Send extra headers

extra_query: Add additional query parameters to the request

extra_body: Add additional JSON properties to the request

timeout: Override the client-level default timeout for this request, in seconds
"""
...

@overload
def continue_(
self,
turn_id: str,
*,
agent_id: str,
session_id: str,
new_messages: Iterable[turn_continue_params.NewMessage],
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> Turn:
"""
Args:
extra_headers: Send extra headers

extra_query: Add additional query parameters to the request

extra_body: Add additional JSON properties to the request

timeout: Override the client-level default timeout for this request, in seconds
"""
...

@required_args(["agent_id", "session_id", "new_messages"])
def continue_(
self,
turn_id: str,
*,
agent_id: str,
session_id: str,
new_messages: Iterable[turn_continue_params.NewMessage],
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> Turn | Stream[AgentTurnResponseStreamChunk]:
if not agent_id:
raise ValueError(f"Expected a non-empty value for `agent_id` but received {agent_id!r}")
if not session_id:
raise ValueError(f"Expected a non-empty value for `session_id` but received {session_id!r}")
if not turn_id:
raise ValueError(f"Expected a non-empty value for `turn_id` but received {turn_id!r}")
return self._post(
f"/v1/agents/{agent_id}/session/{session_id}/turn/{turn_id}/continue",
body=maybe_transform({"new_messages": new_messages}, turn_continue_params.TurnContinueParams),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
cast_to=Turn,
stream=stream or False,
stream_cls=Stream[AgentTurnResponseStreamChunk],
)


class AsyncTurnResource(AsyncAPIResource):
@cached_property
Expand Down Expand Up @@ -421,6 +507,92 @@ async def retrieve(
cast_to=Turn,
)

@overload
async def continue_(
self,
turn_id: str,
*,
agent_id: str,
session_id: str,
new_messages: Iterable[turn_continue_params.NewMessage],
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> Turn:
"""
Args:
extra_headers: Send extra headers

extra_query: Add additional query parameters to the request

extra_body: Add additional JSON properties to the request

timeout: Override the client-level default timeout for this request, in seconds
"""
...

@overload
async def continue_(
self,
turn_id: str,
*,
agent_id: str,
session_id: str,
new_messages: Iterable[turn_continue_params.NewMessage],
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> Turn:
"""
Args:
extra_headers: Send extra headers

extra_query: Add additional query parameters to the request

extra_body: Add additional JSON properties to the request

timeout: Override the client-level default timeout for this request, in seconds
"""
...

@required_args(["agent_id", "session_id", "new_messages"])
async def continue_(
self,
turn_id: str,
*,
agent_id: str,
session_id: str,
new_messages: Iterable[turn_continue_params.NewMessage],
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> Turn | AsyncStream[AgentTurnResponseStreamChunk]:
if not agent_id:
raise ValueError(f"Expected a non-empty value for `agent_id` but received {agent_id!r}")
if not session_id:
raise ValueError(f"Expected a non-empty value for `session_id` but received {session_id!r}")
if not turn_id:
raise ValueError(f"Expected a non-empty value for `turn_id` but received {turn_id!r}")
return await self._post(
f"/v1/agents/{agent_id}/session/{session_id}/turn/{turn_id}/continue",
body=await async_maybe_transform({"new_messages": new_messages}, turn_continue_params.TurnContinueParams),
options=make_request_options(
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
),
cast_to=Turn,
stream=stream or False,
stream_cls=AsyncStream[AgentTurnResponseStreamChunk],
)


class TurnResourceWithRawResponse:
def __init__(self, turn: TurnResource) -> None:
Expand All @@ -432,6 +604,9 @@ def __init__(self, turn: TurnResource) -> None:
self.retrieve = to_raw_response_wrapper(
turn.retrieve,
)
self.continue_ = to_raw_response_wrapper(
turn.continue_,
)


class AsyncTurnResourceWithRawResponse:
Expand All @@ -444,6 +619,9 @@ def __init__(self, turn: AsyncTurnResource) -> None:
self.retrieve = async_to_raw_response_wrapper(
turn.retrieve,
)
self.continue_ = async_to_raw_response_wrapper(
turn.continue_,
)


class TurnResourceWithStreamingResponse:
Expand All @@ -456,6 +634,9 @@ def __init__(self, turn: TurnResource) -> None:
self.retrieve = to_streamed_response_wrapper(
turn.retrieve,
)
self.continue_ = to_streamed_response_wrapper(
turn.continue_,
)


class AsyncTurnResourceWithStreamingResponse:
Expand All @@ -468,3 +649,6 @@ def __init__(self, turn: AsyncTurnResource) -> None:
self.retrieve = async_to_streamed_response_wrapper(
turn.retrieve,
)
self.continue_ = async_to_streamed_response_wrapper(
turn.continue_,
)
1 change: 1 addition & 0 deletions src/llama_stack_client/types/agents/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from .session import Session as Session
from .turn_create_params import TurnCreateParams as TurnCreateParams
from .turn_response_event import TurnResponseEvent as TurnResponseEvent
from .turn_continue_params import TurnContinueParams as TurnContinueParams
from .session_create_params import SessionCreateParams as SessionCreateParams
from .step_retrieve_response import StepRetrieveResponse as StepRetrieveResponse
from .session_create_response import SessionCreateResponse as SessionCreateResponse
Expand Down
33 changes: 33 additions & 0 deletions src/llama_stack_client/types/agents/turn_continue_params.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

from __future__ import annotations

from typing import Union, Iterable
from typing_extensions import Required, TypeAlias, TypedDict

from ..shared_params.user_message import UserMessage
from ..shared_params.tool_response_message import ToolResponseMessage

__all__ = ["TurnContinueParamsBase", "NewMessage", "TurnContinueParamsNonStreaming"]


class TurnContinueParamsBase(TypedDict, total=False):
agent_id: Required[str]

session_id: Required[str]

new_messages: Required[Iterable[NewMessage]]


NewMessage: TypeAlias = Union[UserMessage, ToolResponseMessage]


class TurnContinueParamsNonStreaming(TurnContinueParamsBase, total=False):
pass


class TurnContinueParamsNonStreaming(TurnContinueParamsBase, total=False):
pass


TurnContinueParams = Union[TurnContinueParamsNonStreaming, TurnContinueParamsNonStreaming]
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"AgentTurnResponseStepCompletePayloadStepDetails",
"AgentTurnResponseTurnStartPayload",
"AgentTurnResponseTurnCompletePayload",
"AgentTurnResponseTurnAwaitingInputPayload",
]


Expand Down Expand Up @@ -72,13 +73,21 @@ class AgentTurnResponseTurnCompletePayload(BaseModel):
"""A single turn in an interaction with an Agentic System."""


class AgentTurnResponseTurnAwaitingInputPayload(BaseModel):
event_type: Literal["turn_awaiting_input"]

turn: Turn
"""A single turn in an interaction with an Agentic System."""


TurnResponseEventPayload: TypeAlias = Annotated[
Union[
AgentTurnResponseStepStartPayload,
AgentTurnResponseStepProgressPayload,
AgentTurnResponseStepCompletePayload,
AgentTurnResponseTurnStartPayload,
AgentTurnResponseTurnCompletePayload,
AgentTurnResponseTurnAwaitingInputPayload,
],
PropertyInfo(discriminator="event_type"),
]
Loading