8000 Proxy playground agent by yannbu · Pull Request #268 · WorkflowAI/WorkflowAI · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Proxy playground agent #268

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 15, 2025
Merged
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
10000
52 changes: 52 additions & 0 deletions api/api/routers/agents/meta_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ async def get_meta_agent_chat(
user_properties: UserPropertiesDep,
meta_agent_service: MetaAgentServiceDep,
) -> StreamingResponse:
"""
async def _stream() -> AsyncIterator[BaseModel]:
async for messages in meta_agent_service.stream_meta_agent_response(
task_tuple=task_tuple,
Expand All @@ -97,5 +98,56 @@ async def _stream() -> AsyncIterator[BaseModel]:
playground_state=request.playground_state,
):
yield MetaAgentChatResponse(messages=messages)
"""

# TODO: plug back the legacy proxy meta agent
async def _proxy_stream() -> AsyncIterator[BaseModel]:
async for messages in meta_agent_service.stream_proxy_meta_agent_response(
task_tuple=task_tuple,
agent_schema_id=request.schema_id,
user_email=user_properties.user_email,
messages=request.messages,
):
yield MetaAgentChatResponse(messages=messages)

return safe_streaming_response(_proxy_stream)


class ProxyMetaAgentChatRequest(BaseModel):
# Schema id is passed here instead of as a path parameters in order to have the endpoint schema-agnostic since
# the schema id might change in the middle of the conversation based on the agent's actions.
schema_id: TaskSchemaID
messages: list[MetaAgentChatMessage] = Field(
description="The list of messages in the conversation, the last message being the most recent one",
)


@router.post(
"/proxy/messages",
description="To chat with WorkflowAI's meta agent",
responses={
200: {
"content": {
"text/event-stream": {
"schema": MetaAgentChatResponse.model_json_schema(),
},
},
},
},
)
async def get_proxy_chat_answer(
task_tuple: TaskTupleDep,
request: ProxyMetaAgentChatRequest,
user_properties: UserPropertiesDep,
meta_agent_service: MetaAgentServiceDep,
) -> StreamingResponse:
async def _stream() -> AsyncIterator[BaseModel]:
async for messages in meta_agent_service.stream_proxy_meta_agent_response(
task_tuple=task_tuple,
agent_schema_id=request.schema_id,
user_email=user_properties.user_email,
messages=request.messages,
):
yield MetaAgentChatResponse(messages=messages)

return safe_streaming_response(_stream)
5 changes: 3 additions & 2 deletions api/api/routers/integrations_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
IntegrationChatMessage,
IntegrationChatResponse,
)
from core.domain.integration_domain import OFFICIAL_INTEGRATIONS, IntegrationKind
from core.domain.integration_domain import Integration as DomainIntegration
from core.domain.integration.integration_domain import Integration as DomainIntegration
from core.domain.integration.integration_domain import IntegrationKind
from core.domain.integration.integration_mapping import OFFICIAL_INTEGRATIONS
from core.utils.stream_response_utils import safe_streaming_response

router = APIRouter(prefix="/v1/integrations")
Expand Down
10 changes: 6 additions & 4 deletions api/api/services/internal_tasks/integration_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@
from core.domain.errors import ObjectNotFoundError
from core.domain.events import EventRouter
from core.domain.fields.chat_message import ChatMessage
from core.domain.integration_domain import (
from core.domain.integration.integration_domain import (
Integration,
IntegrationKind,
)
from core.domain.integration.integration_mapping import (
OFFICIAL_INTEGRATIONS,
PROPOSED_AGENT_NAME_AND_MODEL_PLACEHOLDER,
WORKFLOWAI_API_KEY_PLACEHOLDER,
Integration,
IntegrationKind,
)
from core.domain.task_variant import SerializableTaskVariant
from core.domain.users import User
Expand Down Expand Up @@ -255,7 +257,7 @@ async def _find_relevant_run_and_agent(
The goals of this functions is to spot a run / agent that was (very likely) created by the user currently doing the onboarding flow.
"""

async for run in self.storage.task_runs.list_runs_since(
async for run in self.storage.task_runs.list_latest_runs(
since_date=discussion_started_at,
is_active=True, # TODO: filter on proxy runs
limit=2, # TODO: pick a better limit
Expand Down
16 changes: 8 additions & 8 deletions api/api/services/internal_tasks/integration_service_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
from core.domain.agent_run import AgentRun
from core.domain.errors import ObjectNotFoundError
from core.domain.events import EventRouter
from core.domain.integration_domain import (
OFFICIAL_INTEGRATIONS,
from core.domain.integration.integration_domain import (
Integration,
IntegrationKind,
)
from core.domain.integration.integration_mapping import OFFICIAL_INTEGRATIONS
from core.domain.task_variant import SerializableTaskVariant
from core.domain.users import User
from core.storage.backend_storage import BackendStorage
Expand Down Expand Up @@ -208,7 +208,7 @@ def test_get_agent_naming_code_snippet(
assert result.role == "ASSISTANT"
assert result.message_kind == MessageKind.agent_naming_code_snippet
assert proposed_agent_name in result.content
assert f"[{proposed_agent_name}/" in result.content
assert f"{proposed_agent_name}/" in result.content


class TestHasSentAgentNamingCodeSnippet:
Expand Down Expand Up @@ -285,8 +285,8 @@ async def test_find_relevant_run_no_runs(
integration_service: IntegrationService,
):
start_time = datetime.datetime.now()
# Mock list_runs_since to return an async iterator
integration_service.storage.task_runs.list_runs_since = lambda *args, **kwargs: mock_aiter() # type: ignore[reportUnknownLambdaType]
# Mock list_latest_runs to return an async iterator
integration_service.storage.task_runs.list_latest_runs = lambda *args, **kwargs: mock_aiter() # type: ignore[reportUnknownLambdaType]

result = await integration_service._find_relevant_run_and_agent(start_time) # pyright: ignore[reportPrivateUsage]
assert result is None
Expand All @@ -306,7 +306,7 @@ async def test_find_relevant_run_default_agent(
mock_agent.name = DEFAULT_AGENT_ID

# Setup the storage mock to return our mock run and agent
integration_service.storage.task_runs.list_runs_since = lambda *args, **kwargs: mock_aiter(mock_run) # type: ignore[reportUnknownLambdaType]
integration_service.storage.task_runs.list_latest_runs = lambda *args, **kwargs: mock_aiter(mock_run) # type: ignore[reportUnknownLambdaType]

# Patch the _get_agent_by_uid method to return our mock agent
with patch.object(
Expand Down Expand Up @@ -337,7 +337,7 @@ async def test_find_relevant_run_new_named_agent(
mock_agent.created_at = start_time + datetime.timedelta(minutes=5)

# Setup the storage mock to return our mock run and agent
integration_service.storage.task_runs.list_runs_since = lambda *args, **kwargs: mock_aiter(mock_run) # type: ignore[reportUnknownLambdaType]
integration_service.storage.task_runs.list_latest_runs = lambda *args, **kwargs: mock_aiter(mock_run) # type: ignore[reportUnknownLambdaType]

# Patch the _get_agent_by_uid method to return our mock agent
with patch.object(
Expand Down Expand Up @@ -368,7 +368,7 @@ async def test_find_relevant_run_ignore_old_named_agent(
mock_agent.created_at = start_time - datetime.timedelta(minutes=5)

# Setup the storage mock to return our mock run and agent
integration_service.storage.task_runs.list_runs_since = lambda *args, **kwargs: mock_aiter(mock_run) # pyright: ignore[reportAttributeAccessIssue, reportUnknownLambdaType]
integration_service.storage.task_runs.list_latest_runs = lambda *args, **kwargs: mock_aiter(mock_run) # pyright: ignore[reportAttributeAccessIssue, reportUnknownLambdaType]

# Patch the _get_agent_by_uid method to return our mock agent
with patch.object(
Expand Down
Loading
0