agentex-sdk 0.2.0__py3-none-any.whl → 0.2.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- agentex/_version.py +1 -1
- agentex/lib/adk/_modules/acp.py +2 -1
- agentex/lib/adk/_modules/agent_task_tracker.py +2 -1
- agentex/lib/adk/_modules/agents.py +2 -1
- agentex/lib/adk/_modules/events.py +2 -1
- agentex/lib/adk/_modules/messages.py +4 -3
- agentex/lib/adk/_modules/state.py +2 -1
- agentex/lib/adk/_modules/streaming.py +4 -3
- agentex/lib/adk/_modules/tasks.py +2 -1
- agentex/lib/adk/_modules/tracing.py +2 -1
- agentex/lib/adk/providers/_modules/litellm.py +2 -2
- agentex/lib/adk/providers/_modules/openai.py +2 -2
- agentex/lib/adk/utils/_modules/client.py +12 -0
- agentex/lib/cli/commands/init.py +8 -4
- agentex/lib/cli/templates/default/README.md.j2 +23 -2
- agentex/lib/cli/templates/default/dev.ipynb.j2 +126 -0
- agentex/lib/cli/templates/sync/README.md.j2 +22 -2
- agentex/lib/cli/templates/sync/dev.ipynb.j2 +167 -0
- agentex/lib/cli/templates/sync/project/acp.py.j2 +63 -14
- agentex/lib/cli/templates/temporal/README.md.j2 +24 -3
- agentex/lib/cli/templates/temporal/dev.ipynb.j2 +126 -0
- agentex/lib/core/adapters/streams/adapter_redis.py +4 -4
- agentex/lib/core/adapters/streams/port.py +1 -1
- agentex/lib/core/services/adk/streaming.py +2 -3
- agentex/lib/core/temporal/activities/__init__.py +2 -2
- agentex/lib/sdk/fastacp/base/base_acp_server.py +11 -2
- agentex/lib/utils/dev_tools/__init__.py +9 -0
- agentex/lib/utils/dev_tools/async_messages.py +386 -0
- agentex/resources/agents.py +511 -3
- agentex/resources/tasks.py +4 -4
- agentex/types/agent_rpc_response.py +32 -4
- {agentex_sdk-0.2.0.dist-info → agentex_sdk-0.2.2.dist-info}/METADATA +1 -1
- {agentex_sdk-0.2.0.dist-info → agentex_sdk-0.2.2.dist-info}/RECORD +36 -30
- {agentex_sdk-0.2.0.dist-info → agentex_sdk-0.2.2.dist-info}/WHEEL +0 -0
- {agentex_sdk-0.2.0.dist-info → agentex_sdk-0.2.2.dist-info}/entry_points.txt +0 -0
- {agentex_sdk-0.2.0.dist-info → agentex_sdk-0.2.2.dist-info}/licenses/LICENSE +0 -0
agentex/resources/agents.py
CHANGED
@@ -2,7 +2,8 @@
|
|
2
2
|
|
3
3
|
from __future__ import annotations
|
4
4
|
|
5
|
-
|
5
|
+
import json
|
6
|
+
from typing import AsyncGenerator, Generator, Union, Optional
|
6
7
|
from typing_extensions import Literal
|
7
8
|
|
8
9
|
import httpx
|
@@ -20,7 +21,7 @@ from .._response import (
|
|
20
21
|
)
|
21
22
|
from ..types.agent import Agent
|
22
23
|
from .._base_client import make_request_options
|
23
|
-
from ..types.agent_rpc_response import AgentRpcResponse
|
24
|
+
from ..types.agent_rpc_response import AgentRpcResponse, CancelTaskResponse, CreateTaskResponse, SendEventResponse, SendMessageResponse, SendMessageStreamResponse
|
24
25
|
from ..types.agent_list_response import AgentListResponse
|
25
26
|
|
26
27
|
__all__ = ["AgentsResource", "AsyncAgentsResource"]
|
@@ -310,6 +311,260 @@ class AgentsResource(SyncAPIResource):
|
|
310
311
|
),
|
311
312
|
cast_to=AgentRpcResponse,
|
312
313
|
)
|
314
|
+
|
315
|
+
def create_task(
|
316
|
+
self,
|
317
|
+
agent_id: str | None = None,
|
318
|
+
agent_name: str | None = None,
|
319
|
+
*,
|
320
|
+
params: agent_rpc_params.ParamsCreateTaskRequest,
|
321
|
+
id: Union[int, str, None] | NotGiven = NOT_GIVEN,
|
322
|
+
jsonrpc: Literal["2.0"] | NotGiven = NOT_GIVEN,
|
323
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
324
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
325
|
+
extra_headers: Headers | None = None,
|
326
|
+
extra_query: Query | None = None,
|
327
|
+
extra_body: Body | None = None,
|
328
|
+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
329
|
+
) -> CreateTaskResponse:
|
330
|
+
if agent_id is not None and agent_name is not None:
|
331
|
+
raise ValueError("Either agent_id or agent_name must be provided, but not both")
|
332
|
+
|
333
|
+
if agent_id is not None:
|
334
|
+
raw_agent_rpc_response = self.rpc(
|
335
|
+
agent_id=agent_id,
|
336
|
+
method="task/create",
|
337
|
+
params=params,
|
338
|
+
id=id,
|
339
|
+
jsonrpc=jsonrpc,
|
340
|
+
extra_headers=extra_headers,
|
341
|
+
extra_query=extra_query,
|
342
|
+
extra_body=extra_body,
|
343
|
+
timeout=timeout,
|
344
|
+
)
|
345
|
+
elif agent_name is not None:
|
346
|
+
raw_agent_rpc_response = self.rpc_by_name(
|
347
|
+
agent_name=agent_name,
|
348
|
+
method="task/create",
|
349
|
+
params=params,
|
350
|
+
id=id,
|
351
|
+
jsonrpc=jsonrpc,
|
352
|
+
extra_headers=extra_headers,
|
353
|
+
extra_query=extra_query,
|
354
|
+
extra_body=extra_body,
|
355
|
+
timeout=timeout,
|
356
|
+
)
|
357
|
+
else:
|
358
|
+
raise ValueError("Either agent_id or agent_name must be provided")
|
359
|
+
|
360
|
+
return CreateTaskResponse.model_validate(raw_agent_rpc_response, from_attributes=True)
|
361
|
+
|
362
|
+
def cancel_task(
|
363
|
+
self,
|
364
|
+
agent_id: str | None = None,
|
365
|
+
agent_name: str | None = None,
|
366
|
+
*,
|
367
|
+
params: agent_rpc_params.ParamsCancelTaskRequest,
|
368
|
+
id: Union[int, str, None] | NotGiven = NOT_GIVEN,
|
369
|
+
jsonrpc: Literal["2.0"] | NotGiven = NOT_GIVEN,
|
370
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
371
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
372
|
+
extra_headers: Headers | None = None,
|
373
|
+
extra_query: Query | None = None,
|
374
|
+
extra_body: Body | None = None,
|
375
|
+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
376
|
+
) -> CancelTaskResponse:
|
377
|
+
if agent_id is not None and agent_name is not None:
|
378
|
+
raise ValueError("Either agent_id or agent_name must be provided, but not both")
|
379
|
+
|
380
|
+
if agent_id is not None:
|
381
|
+
raw_agent_rpc_response = self.rpc(
|
382
|
+
agent_id=agent_id,
|
383
|
+
method="task/cancel",
|
384
|
+
params=params,
|
385
|
+
id=id,
|
386
|
+
jsonrpc=jsonrpc,
|
387
|
+
extra_headers=extra_headers,
|
388
|
+
extra_query=extra_query,
|
389
|
+
extra_body=extra_body,
|
390
|
+
timeout=timeout,
|
391
|
+
)
|
392
|
+
elif agent_name is not None:
|
393
|
+
raw_agent_rpc_response = self.rpc_by_name(
|
394
|
+
agent_name=agent_name,
|
395
|
+
method="task/cancel",
|
396
|
+
params=params,
|
397
|
+
id=id,
|
398
|
+
jsonrpc=jsonrpc,
|
399
|
+
extra_headers=extra_headers,
|
400
|
+
extra_query=extra_query,
|
401
|
+
extra_body=extra_body,
|
402
|
+
timeout=timeout,
|
403
|
+
)
|
404
|
+
else:
|
405
|
+
raise ValueError("Either agent_id or agent_name must be provided")
|
406
|
+
|
407
|
+
return CancelTaskResponse.model_validate(raw_agent_rpc_response, from_attributes=True)
|
408
|
+
|
409
|
+
def send_message(
|
410
|
+
self,
|
411
|
+
agent_id: str | None = None,
|
412
|
+
agent_name: str | None = None,
|
413
|
+
*,
|
414
|
+
params: agent_rpc_params.ParamsSendMessageRequest,
|
415
|
+
id: Union[int, str, None] | NotGiven = NOT_GIVEN,
|
416
|
+
jsonrpc: Literal["2.0"] | NotGiven = NOT_GIVEN,
|
417
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
418
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
419
|
+
extra_headers: Headers | None = None,
|
420
|
+
extra_query: Query | None = None,
|
421
|
+
extra_body: Body | None = None,
|
422
|
+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
423
|
+
) -> SendMessageResponse:
|
424
|
+
if agent_id is not None and agent_name is not None:
|
425
|
+
raise ValueError("Either agent_id or agent_name must be provided, but not both")
|
426
|
+
|
427
|
+
if "stream" in params and params["stream"] == True:
|
428
|
+
raise ValueError("If stream is set to True, use send_message_stream() instead")
|
429
|
+
else:
|
430
|
+
if agent_id is not None:
|
431
|
+
raw_agent_rpc_response = self.rpc(
|
432
|
+
agent_id=agent_id,
|
433
|
+
method="message/send",
|
434
|
+
params=params,
|
435
|
+
id=id,
|
436
|
+
jsonrpc=jsonrpc,
|
437
|
+
extra_headers=extra_headers,
|
438
|
+
extra_query=extra_query,
|
439
|
+
extra_body=extra_body,
|
440
|
+
timeout=timeout,
|
441
|
+
)
|
442
|
+
elif agent_name is not None:
|
443
|
+
raw_agent_rpc_response = self.rpc_by_name(
|
444
|
+
agent_name=agent_name,
|
445
|
+
method="message/send",
|
446
|
+
params=params,
|
447
|
+
id=id,
|
448
|
+
jsonrpc=jsonrpc,
|
449
|
+
extra_headers=extra_headers,
|
450
|
+
extra_query=extra_query,
|
451
|
+
extra_body=extra_body,
|
452
|
+
timeout=timeout,
|
453
|
+
)
|
454
|
+
else:
|
455
|
+
raise ValueError("Either agent_id or agent_name must be provided")
|
456
|
+
|
457
|
+
return SendMessageResponse.model_validate(raw_agent_rpc_response, from_attributes=True)
|
458
|
+
|
459
|
+
def send_message_stream(
|
460
|
+
self,
|
461
|
+
agent_id: str | None = None,
|
462
|
+
agent_name: str | None = None,
|
463
|
+
*,
|
464
|
+
params: agent_rpc_params.ParamsSendMessageRequest,
|
465
|
+
id: Union[int, str, None] | NotGiven = NOT_GIVEN,
|
466
|
+
jsonrpc: Literal["2.0"] | NotGiven = NOT_GIVEN,
|
467
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
468
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
469
|
+
extra_headers: Headers | None = None,
|
470
|
+
extra_query: Query | None = None,
|
471
|
+
extra_body: Body | None = None,
|
472
|
+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
473
|
+
) -> Generator[SendMessageStreamResponse, None, None]:
|
474
|
+
if agent_id is not None and agent_name is not None:
|
475
|
+
raise ValueError("Either agent_id or agent_name must be provided, but not both")
|
476
|
+
|
477
|
+
if "stream" in params and params["stream"] == False:
|
478
|
+
raise ValueError("If stream is set to False, use send_message() instead")
|
479
|
+
|
480
|
+
params["stream"] = True
|
481
|
+
|
482
|
+
if agent_id is not None:
|
483
|
+
raw_agent_rpc_response = self.with_streaming_response.rpc(
|
484
|
+
agent_id=agent_id,
|
485
|
+
method="message/send",
|
486
|
+
params=params,
|
487
|
+
id=id,
|
488
|
+
jsonrpc=jsonrpc,
|
489
|
+
extra_headers=extra_headers,
|
490
|
+
extra_query=extra_query,
|
491
|
+
extra_body=extra_body,
|
492
|
+
timeout=timeout,
|
493
|
+
)
|
494
|
+
elif agent_name is not None:
|
495
|
+
raw_agent_rpc_response = self.with_streaming_response.rpc_by_name(
|
496
|
+
agent_name=agent_name,
|
497
|
+
method="message/send",
|
498
|
+
params=params,
|
499
|
+
id=id,
|
500
|
+
jsonrpc=jsonrpc,
|
501
|
+
extra_headers=extra_headers,
|
502
|
+
extra_query=extra_query,
|
503
|
+
extra_body=extra_body,
|
504
|
+
timeout=timeout,
|
505
|
+
)
|
506
|
+
else:
|
507
|
+
raise ValueError("Either agent_id or agent_name must be provided")
|
508
|
+
|
509
|
+
with raw_agent_rpc_response as response:
|
510
|
+
for agent_rpc_response_str in response.iter_text():
|
511
|
+
if agent_rpc_response_str.strip(): # Only process non-empty lines
|
512
|
+
try:
|
513
|
+
chunk_rpc_response = SendMessageStreamResponse.model_validate(
|
514
|
+
json.loads(agent_rpc_response_str),
|
515
|
+
from_attributes=True
|
516
|
+
)
|
517
|
+
yield chunk_rpc_response
|
518
|
+
except json.JSONDecodeError:
|
519
|
+
# Skip invalid JSON lines
|
520
|
+
continue
|
521
|
+
|
522
|
+
def send_event(
|
523
|
+
self,
|
524
|
+
agent_id: str | None = None,
|
525
|
+
agent_name: str | None = None,
|
526
|
+
*,
|
527
|
+
params: agent_rpc_params.ParamsSendEventRequest,
|
528
|
+
id: Union[int, str, None] | NotGiven = NOT_GIVEN,
|
529
|
+
jsonrpc: Literal["2.0"] | NotGiven = NOT_GIVEN,
|
530
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
531
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
532
|
+
extra_headers: Headers | None = None,
|
533
|
+
extra_query: Query | None = None,
|
534
|
+
extra_body: Body | None = None,
|
535
|
+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
536
|
+
) -> SendEventResponse:
|
537
|
+
if agent_id is not None and agent_name is not None:
|
538
|
+
raise ValueError("Either agent_id or agent_name must be provided, but not both")
|
539
|
+
|
540
|
+
if agent_id is not None:
|
541
|
+
raw_agent_rpc_response = self.rpc(
|
542
|
+
agent_id=agent_id,
|
543
|
+
method="event/send",
|
544
|
+
params=params,
|
545
|
+
id=id,
|
546
|
+
jsonrpc=jsonrpc,
|
547
|
+
extra_headers=extra_headers,
|
548
|
+
extra_query=extra_query,
|
549
|
+
extra_body=extra_body,
|
550
|
+
timeout=timeout,
|
551
|
+
)
|
552
|
+
elif agent_name is not None:
|
553
|
+
raw_agent_rpc_response = self.rpc_by_name(
|
554
|
+
agent_name=agent_name,
|
555
|
+
method="event/send",
|
556
|
+
params=params,
|
557
|
+
id=id,
|
558
|
+
jsonrpc=jsonrpc,
|
559
|
+
extra_headers=extra_headers,
|
560
|
+
extra_query=extra_query,
|
561
|
+
extra_body=extra_body,
|
562
|
+
timeout=timeout,
|
563
|
+
)
|
564
|
+
else:
|
565
|
+
raise ValueError("Either agent_id or agent_name must be provided")
|
566
|
+
|
567
|
+
return SendEventResponse.model_validate(raw_agent_rpc_response, from_attributes=True)
|
313
568
|
|
314
569
|
|
315
570
|
class AsyncAgentsResource(AsyncAPIResource):
|
@@ -596,7 +851,260 @@ class AsyncAgentsResource(AsyncAPIResource):
|
|
596
851
|
),
|
597
852
|
cast_to=AgentRpcResponse,
|
598
853
|
)
|
599
|
-
|
854
|
+
|
855
|
+
async def create_task(
|
856
|
+
self,
|
857
|
+
agent_id: str | None = None,
|
858
|
+
agent_name: str | None = None,
|
859
|
+
*,
|
860
|
+
params: agent_rpc_params.ParamsCreateTaskRequest,
|
861
|
+
id: Union[int, str, None] | NotGiven = NOT_GIVEN,
|
862
|
+
jsonrpc: Literal["2.0"] | NotGiven = NOT_GIVEN,
|
863
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
864
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
865
|
+
extra_headers: Headers | None = None,
|
866
|
+
extra_query: Query | None = None,
|
867
|
+
extra_body: Body | None = None,
|
868
|
+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
869
|
+
) -> CreateTaskResponse:
|
870
|
+
if agent_id is not None and agent_name is not None:
|
871
|
+
raise ValueError("Either agent_id or agent_name must be provided, but not both")
|
872
|
+
|
873
|
+
if agent_id is not None:
|
874
|
+
raw_agent_rpc_response = await self.rpc(
|
875
|
+
agent_id=agent_id,
|
876
|
+
method="task/create",
|
877
|
+
params=params,
|
878
|
+
id=id,
|
879
|
+
jsonrpc=jsonrpc,
|
880
|
+
extra_headers=extra_headers,
|
881
|
+
extra_query=extra_query,
|
882
|
+
extra_body=extra_body,
|
883
|
+
timeout=timeout,
|
884
|
+
)
|
885
|
+
elif agent_name is not None:
|
886
|
+
raw_agent_rpc_response = await self.rpc_by_name(
|
887
|
+
agent_name=agent_name,
|
888
|
+
method="task/create",
|
889
|
+
params=params,
|
890
|
+
id=id,
|
891
|
+
jsonrpc=jsonrpc,
|
892
|
+
extra_headers=extra_headers,
|
893
|
+
extra_query=extra_query,
|
894
|
+
extra_body=extra_body,
|
895
|
+
timeout=timeout,
|
896
|
+
)
|
897
|
+
else:
|
898
|
+
raise ValueError("Either agent_id or agent_name must be provided")
|
899
|
+
|
900
|
+
return CreateTaskResponse.model_validate(raw_agent_rpc_response, from_attributes=True)
|
901
|
+
|
902
|
+
async def cancel_task(
|
903
|
+
self,
|
904
|
+
agent_id: str | None = None,
|
905
|
+
agent_name: str | None = None,
|
906
|
+
*,
|
907
|
+
params: agent_rpc_params.ParamsCancelTaskRequest,
|
908
|
+
id: Union[int, str, None] | NotGiven = NOT_GIVEN,
|
909
|
+
jsonrpc: Literal["2.0"] | NotGiven = NOT_GIVEN,
|
910
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
911
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
912
|
+
extra_headers: Headers | None = None,
|
913
|
+
extra_query: Query | None = None,
|
914
|
+
extra_body: Body | None = None,
|
915
|
+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
916
|
+
) -> CancelTaskResponse:
|
917
|
+
if agent_id is not None and agent_name is not None:
|
918
|
+
raise ValueError("Either agent_id or agent_name must be provided, but not both")
|
919
|
+
|
920
|
+
if agent_id is not None:
|
921
|
+
raw_agent_rpc_response = await self.rpc(
|
922
|
+
agent_id=agent_id,
|
923
|
+
method="task/cancel",
|
924
|
+
params=params,
|
925
|
+
id=id,
|
926
|
+
jsonrpc=jsonrpc,
|
927
|
+
extra_headers=extra_headers,
|
928
|
+
extra_query=extra_query,
|
929
|
+
extra_body=extra_body,
|
930
|
+
timeout=timeout,
|
931
|
+
)
|
932
|
+
elif agent_name is not None:
|
933
|
+
raw_agent_rpc_response = await self.rpc_by_name(
|
934
|
+
agent_name=agent_name,
|
935
|
+
method="task/cancel",
|
936
|
+
params=params,
|
937
|
+
id=id,
|
938
|
+
jsonrpc=jsonrpc,
|
939
|
+
extra_headers=extra_headers,
|
940
|
+
extra_query=extra_query,
|
941
|
+
extra_body=extra_body,
|
942
|
+
timeout=timeout,
|
943
|
+
)
|
944
|
+
else:
|
945
|
+
raise ValueError("Either agent_id or agent_name must be provided")
|
946
|
+
|
947
|
+
return CancelTaskResponse.model_validate(raw_agent_rpc_response, from_attributes=True)
|
948
|
+
|
949
|
+
async def send_message(
|
950
|
+
self,
|
951
|
+
agent_id: str | None = None,
|
952
|
+
agent_name: str | None = None,
|
953
|
+
*,
|
954
|
+
params: agent_rpc_params.ParamsSendMessageRequest,
|
955
|
+
id: Union[int, str, None] | NotGiven = NOT_GIVEN,
|
956
|
+
jsonrpc: Literal["2.0"] | NotGiven = NOT_GIVEN,
|
957
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
958
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
959
|
+
extra_headers: Headers | None = None,
|
960
|
+
extra_query: Query | None = None,
|
961
|
+
extra_body: Body | None = None,
|
962
|
+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
963
|
+
) -> SendMessageResponse:
|
964
|
+
if agent_id is not None and agent_name is not None:
|
965
|
+
raise ValueError("Either agent_id or agent_name must be provided, but not both")
|
966
|
+
|
967
|
+
if "stream" in params and params["stream"] == True:
|
968
|
+
raise ValueError("If stream is set to True, use send_message_stream() instead")
|
969
|
+
else:
|
970
|
+
if agent_id is not None:
|
971
|
+
raw_agent_rpc_response = await self.rpc(
|
972
|
+
agent_id=agent_id,
|
973
|
+
method="message/send",
|
974
|
+
params=params,
|
975
|
+
id=id,
|
976
|
+
jsonrpc=jsonrpc,
|
977
|
+
extra_headers=extra_headers,
|
978
|
+
extra_query=extra_query,
|
979
|
+
extra_body=extra_body,
|
980
|
+
timeout=timeout,
|
981
|
+
)
|
982
|
+
elif agent_name is not None:
|
983
|
+
raw_agent_rpc_response = await self.rpc_by_name(
|
984
|
+
agent_name=agent_name,
|
985
|
+
method="message/send",
|
986
|
+
params=params,
|
987
|
+
id=id,
|
988
|
+
jsonrpc=jsonrpc,
|
989
|
+
extra_headers=extra_headers,
|
990
|
+
extra_query=extra_query,
|
991
|
+
extra_body=extra_body,
|
992
|
+
timeout=timeout,
|
993
|
+
)
|
994
|
+
else:
|
995
|
+
raise ValueError("Either agent_id or agent_name must be provided")
|
996
|
+
|
997
|
+
return SendMessageResponse.model_validate(raw_agent_rpc_response, from_attributes=True)
|
998
|
+
|
999
|
+
async def send_message_stream(
|
1000
|
+
self,
|
1001
|
+
agent_id: str | None = None,
|
1002
|
+
agent_name: str | None = None,
|
1003
|
+
*,
|
1004
|
+
params: agent_rpc_params.ParamsSendMessageRequest,
|
1005
|
+
id: Union[int, str, None] | NotGiven = NOT_GIVEN,
|
1006
|
+
jsonrpc: Literal["2.0"] | NotGiven = NOT_GIVEN,
|
1007
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
1008
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
1009
|
+
extra_headers: Headers | None = None,
|
1010
|
+
extra_query: Query | None = None,
|
1011
|
+
extra_body: Body | None = None,
|
1012
|
+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
1013
|
+
) -> AsyncGenerator[SendMessageStreamResponse, None]:
|
1014
|
+
if agent_id is not None and agent_name is not None:
|
1015
|
+
raise ValueError("Either agent_id or agent_name must be provided, but not both")
|
1016
|
+
|
1017
|
+
if "stream" in params and params["stream"] == False:
|
1018
|
+
raise ValueError("If stream is set to False, use send_message() instead")
|
1019
|
+
|
1020
|
+
params["stream"] = True
|
1021
|
+
|
1022
|
+
if agent_id is not None:
|
1023
|
+
raw_agent_rpc_response = self.with_streaming_response.rpc(
|
1024
|
+
agent_id=agent_id,
|
1025
|
+
method="message/send",
|
1026
|
+
params=params,
|
1027
|
+
id=id,
|
1028
|
+
jsonrpc=jsonrpc,
|
1029
|
+
extra_headers=extra_headers,
|
1030
|
+
extra_query=extra_query,
|
1031
|
+
extra_body=extra_body,
|
1032
|
+
timeout=timeout,
|
1033
|
+
)
|
1034
|
+
elif agent_name is not None:
|
1035
|
+
raw_agent_rpc_response = self.with_streaming_response.rpc_by_name(
|
1036
|
+
agent_name=agent_name,
|
1037
|
+
method="message/send",
|
1038
|
+
params=params,
|
1039
|
+
id=id,
|
1040
|
+
jsonrpc=jsonrpc,
|
1041
|
+
extra_headers=extra_headers,
|
1042
|
+
extra_query=extra_query,
|
1043
|
+
extra_body=extra_body,
|
1044
|
+
timeout=timeout,
|
1045
|
+
)
|
1046
|
+
else:
|
1047
|
+
raise ValueError("Either agent_id or agent_name must be provided")
|
1048
|
+
|
1049
|
+
async with raw_agent_rpc_response as response:
|
1050
|
+
async for agent_rpc_response_str in response.iter_text():
|
1051
|
+
if agent_rpc_response_str.strip(): # Only process non-empty lines
|
1052
|
+
try:
|
1053
|
+
chunk_rpc_response = SendMessageStreamResponse.model_validate(
|
1054
|
+
json.loads(agent_rpc_response_str),
|
1055
|
+
from_attributes=True
|
1056
|
+
)
|
1057
|
+
yield chunk_rpc_response
|
1058
|
+
except json.JSONDecodeError:
|
1059
|
+
# Skip invalid JSON lines
|
1060
|
+
continue
|
1061
|
+
|
1062
|
+
async def send_event(
|
1063
|
+
self,
|
1064
|
+
agent_id: str | None = None,
|
1065
|
+
agent_name: str | None = None,
|
1066
|
+
*,
|
1067
|
+
params: agent_rpc_params.ParamsSendEventRequest,
|
1068
|
+
id: Union[int, str, None] | NotGiven = NOT_GIVEN,
|
1069
|
+
jsonrpc: Literal["2.0"] | NotGiven = NOT_GIVEN,
|
1070
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
1071
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
1072
|
+
extra_headers: Headers | None = None,
|
1073
|
+
extra_query: Query | None = None,
|
1074
|
+
extra_body: Body | None = None,
|
1075
|
+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
1076
|
+
) -> SendEventResponse:
|
1077
|
+
if agent_id is not None and agent_name is not None:
|
1078
|
+
raise ValueError("Either agent_id or agent_name must be provided, but not both")
|
1079
|
+
|
1080
|
+
if agent_id is not None:
|
1081
|
+
raw_agent_rpc_response = await self.rpc(
|
1082
|
+
agent_id=agent_id,
|
1083
|
+
method="event/send",
|
1084
|
+
params=params,
|
1085
|
+
id=id,
|
1086
|
+
jsonrpc=jsonrpc,
|
1087
|
+
extra_headers=extra_headers,
|
1088
|
+
extra_query=extra_query,
|
1089
|
+
extra_body=extra_body,
|
1090
|
+
timeout=timeout,
|
1091
|
+
)
|
1092
|
+
elif agent_name is not None:
|
1093
|
+
raw_agent_rpc_response = await self.rpc_by_name(
|
1094
|
+
agent_name=agent_name,
|
1095
|
+
method="event/send",
|
1096
|
+
params=params,
|
1097
|
+
id=id,
|
1098
|
+
jsonrpc=jsonrpc,
|
1099
|
+
extra_headers=extra_headers,
|
1100
|
+
extra_query=extra_query,
|
1101
|
+
extra_body=extra_body,
|
1102
|
+
timeout=timeout,
|
1103
|
+
)
|
1104
|
+
else:
|
1105
|
+
raise ValueError("Either agent_id or agent_name must be provided")
|
1106
|
+
|
1107
|
+
return SendEventResponse.model_validate(raw_agent_rpc_response, from_attributes=True)
|
600
1108
|
|
601
1109
|
class AgentsResourceWithRawResponse:
|
602
1110
|
def __init__(self, agents: AgentsResource) -> None:
|
agentex/resources/tasks.py
CHANGED
@@ -206,7 +206,7 @@ class TasksResource(SyncAPIResource):
|
|
206
206
|
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
207
207
|
) -> Stream[object]:
|
208
208
|
"""
|
209
|
-
Stream
|
209
|
+
Stream message updates for a task by its unique ID.
|
210
210
|
|
211
211
|
Args:
|
212
212
|
extra_headers: Send extra headers
|
@@ -241,7 +241,7 @@ class TasksResource(SyncAPIResource):
|
|
241
241
|
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
242
242
|
) -> Stream[object]:
|
243
243
|
"""
|
244
|
-
Stream
|
244
|
+
Stream message updates for a task by its unique name.
|
245
245
|
|
246
246
|
Args:
|
247
247
|
extra_headers: Send extra headers
|
@@ -448,7 +448,7 @@ class AsyncTasksResource(AsyncAPIResource):
|
|
448
448
|
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
449
449
|
) -> AsyncStream[object]:
|
450
450
|
"""
|
451
|
-
Stream
|
451
|
+
Stream message updates for a task by its unique ID.
|
452
452
|
|
453
453
|
Args:
|
454
454
|
extra_headers: Send extra headers
|
@@ -483,7 +483,7 @@ class AsyncTasksResource(AsyncAPIResource):
|
|
483
483
|
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
484
484
|
) -> AsyncStream[object]:
|
485
485
|
"""
|
486
|
-
Stream
|
486
|
+
Stream message updates for a task by its unique name.
|
487
487
|
|
488
488
|
Args:
|
489
489
|
extra_headers: Send extra headers
|
@@ -5,16 +5,44 @@ from typing_extensions import Literal
|
|
5
5
|
|
6
6
|
from .._models import BaseModel
|
7
7
|
from .agent_rpc_result import AgentRpcResult
|
8
|
+
from .event import Event
|
9
|
+
from .task import Task
|
10
|
+
from .task_message import TaskMessage
|
11
|
+
from .task_message_update import TaskMessageUpdate
|
8
12
|
|
9
13
|
__all__ = ["AgentRpcResponse"]
|
10
14
|
|
11
15
|
|
12
|
-
class
|
16
|
+
class BaseAgentRpcResponse(BaseModel):
|
17
|
+
id: Union[int, str, None] = None
|
18
|
+
error: Optional[object] = None
|
19
|
+
jsonrpc: Optional[Literal["2.0"]] = None
|
20
|
+
|
21
|
+
|
22
|
+
class AgentRpcResponse(BaseAgentRpcResponse):
|
13
23
|
result: Optional[AgentRpcResult] = None
|
14
24
|
"""The result of the agent RPC request"""
|
15
25
|
|
16
|
-
id: Union[int, str, None] = None
|
17
26
|
|
18
|
-
|
27
|
+
class CreateTaskResponse(BaseAgentRpcResponse):
|
28
|
+
result: Task
|
29
|
+
"""The result of the task creation"""
|
19
30
|
|
20
|
-
|
31
|
+
|
32
|
+
class CancelTaskResponse(BaseAgentRpcResponse):
|
33
|
+
result: Task
|
34
|
+
"""The result of the task cancellation"""
|
35
|
+
|
36
|
+
|
37
|
+
class SendMessageResponse(BaseAgentRpcResponse):
|
38
|
+
result: list[TaskMessage]
|
39
|
+
"""The result of the message sending"""
|
40
|
+
|
41
|
+
class SendMessageStreamResponse(BaseAgentRpcResponse):
|
42
|
+
result: TaskMessageUpdate
|
43
|
+
"""The result of the message sending"""
|
44
|
+
|
45
|
+
|
46
|
+
class SendEventResponse(BaseAgentRpcResponse):
|
47
|
+
result: Event
|
48
|
+
"""The result of the event sending"""
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.3
|
2
2
|
Name: agentex-sdk
|
3
|
-
Version: 0.2.
|
3
|
+
Version: 0.2.2
|
4
4
|
Summary: The official Python library for the agentex API
|
5
5
|
Project-URL: Homepage, https://github.com/scaleapi/agentex-python
|
6
6
|
Project-URL: Repository, https://github.com/scaleapi/agentex-python
|