letta-client 0.1.19__py3-none-any.whl → 0.1.21__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.
- letta_client/__init__.py +10 -0
- letta_client/agents/__init__.py +2 -1
- letta_client/agents/archival_memory/client.py +218 -25
- letta_client/agents/client.py +350 -1637
- letta_client/agents/core_memory/client.py +424 -97
- letta_client/agents/memory_variables/client.py +2 -2
- letta_client/agents/messages/__init__.py +2 -2
- letta_client/agents/messages/client.py +19 -14
- letta_client/agents/messages/types/__init__.py +2 -1
- letta_client/agents/messages/types/message_update_content.py +6 -0
- letta_client/blocks/client.py +127 -0
- letta_client/core/client_wrapper.py +1 -1
- letta_client/providers/client.py +6 -6
- letta_client/runs/client.py +30 -18
- letta_client/sources/files/client.py +6 -6
- letta_client/tag/client.py +6 -6
- letta_client/tools/client.py +6 -6
- letta_client/types/__init__.py +10 -0
- letta_client/types/assistant_message.py +2 -1
- letta_client/types/assistant_message_content.py +6 -0
- letta_client/types/llm_config.py +6 -0
- letta_client/types/message.py +3 -2
- letta_client/types/message_create.py +3 -2
- letta_client/types/message_create_content.py +6 -0
- letta_client/types/system_message.py +3 -2
- letta_client/types/system_message_content.py +6 -0
- letta_client/types/text_content.py +23 -0
- letta_client/types/user_message.py +3 -2
- letta_client/types/user_message_content.py +6 -0
- {letta_client-0.1.19.dist-info → letta_client-0.1.21.dist-info}/METADATA +2 -2
- {letta_client-0.1.19.dist-info → letta_client-0.1.21.dist-info}/RECORD +32 -26
- {letta_client-0.1.19.dist-info → letta_client-0.1.21.dist-info}/WHEEL +0 -0
letta_client/agents/client.py
CHANGED
|
@@ -5,11 +5,11 @@ from ..core.client_wrapper import SyncClientWrapper
|
|
|
5
5
|
from .context.client import ContextClient
|
|
6
6
|
from .tools.client import ToolsClient
|
|
7
7
|
from .sources.client import SourcesClient
|
|
8
|
+
from .core_memory.client import CoreMemoryClient
|
|
9
|
+
from .archival_memory.client import ArchivalMemoryClient
|
|
8
10
|
from .messages.client import MessagesClient
|
|
9
11
|
from .templates.client import TemplatesClient
|
|
10
12
|
from .memory_variables.client import MemoryVariablesClient
|
|
11
|
-
from .core_memory.client import CoreMemoryClient
|
|
12
|
-
from .archival_memory.client import ArchivalMemoryClient
|
|
13
13
|
from ..core.request_options import RequestOptions
|
|
14
14
|
from ..types.agent_state import AgentState
|
|
15
15
|
from ..core.unchecked_base_model import construct_type
|
|
@@ -26,20 +26,17 @@ from ..types.message_create import MessageCreate
|
|
|
26
26
|
from ..core.serialization import convert_and_respect_annotation_metadata
|
|
27
27
|
from ..core.jsonable_encoder import jsonable_encoder
|
|
28
28
|
from .types.update_agent_tool_rules_item import UpdateAgentToolRulesItem
|
|
29
|
-
from ..types.memory import Memory
|
|
30
|
-
from ..types.block import Block
|
|
31
|
-
from ..types.passage import Passage
|
|
32
29
|
from .types.agents_search_request_search_item import AgentsSearchRequestSearchItem
|
|
33
30
|
from .types.agents_search_request_combinator import AgentsSearchRequestCombinator
|
|
34
31
|
from ..core.client_wrapper import AsyncClientWrapper
|
|
35
32
|
from .context.client import AsyncContextClient
|
|
36
33
|
from .tools.client import AsyncToolsClient
|
|
37
34
|
from .sources.client import AsyncSourcesClient
|
|
35
|
+
from .core_memory.client import AsyncCoreMemoryClient
|
|
36
|
+
from .archival_memory.client import AsyncArchivalMemoryClient
|
|
38
37
|
from .messages.client import AsyncMessagesClient
|
|
39
38
|
from .templates.client import AsyncTemplatesClient
|
|
40
39
|
from .memory_variables.client import AsyncMemoryVariablesClient
|
|
41
|
-
from .core_memory.client import AsyncCoreMemoryClient
|
|
42
|
-
from .archival_memory.client import AsyncArchivalMemoryClient
|
|
43
40
|
|
|
44
41
|
# this is used as the default value for optional parameters
|
|
45
42
|
OMIT = typing.cast(typing.Any, ...)
|
|
@@ -51,11 +48,11 @@ class AgentsClient:
|
|
|
51
48
|
self.context = ContextClient(client_wrapper=self._client_wrapper)
|
|
52
49
|
self.tools = ToolsClient(client_wrapper=self._client_wrapper)
|
|
53
50
|
self.sources = SourcesClient(client_wrapper=self._client_wrapper)
|
|
51
|
+
self.core_memory = CoreMemoryClient(client_wrapper=self._client_wrapper)
|
|
52
|
+
self.archival_memory = ArchivalMemoryClient(client_wrapper=self._client_wrapper)
|
|
54
53
|
self.messages = MessagesClient(client_wrapper=self._client_wrapper)
|
|
55
54
|
self.templates = TemplatesClient(client_wrapper=self._client_wrapper)
|
|
56
55
|
self.memory_variables = MemoryVariablesClient(client_wrapper=self._client_wrapper)
|
|
57
|
-
self.core_memory = CoreMemoryClient(client_wrapper=self._client_wrapper)
|
|
58
|
-
self.archival_memory = ArchivalMemoryClient(client_wrapper=self._client_wrapper)
|
|
59
56
|
|
|
60
57
|
def list(
|
|
61
58
|
self,
|
|
@@ -63,7 +60,8 @@ class AgentsClient:
|
|
|
63
60
|
name: typing.Optional[str] = None,
|
|
64
61
|
tags: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
|
|
65
62
|
match_all_tags: typing.Optional[bool] = None,
|
|
66
|
-
|
|
63
|
+
before: typing.Optional[str] = None,
|
|
64
|
+
after: typing.Optional[str] = None,
|
|
67
65
|
limit: typing.Optional[int] = None,
|
|
68
66
|
query_text: typing.Optional[str] = None,
|
|
69
67
|
request_options: typing.Optional[RequestOptions] = None,
|
|
@@ -83,7 +81,10 @@ class AgentsClient:
|
|
|
83
81
|
match_all_tags : typing.Optional[bool]
|
|
84
82
|
If True, only returns agents that match ALL given tags. Otherwise, return agents that have ANY of the passed in tags.
|
|
85
83
|
|
|
86
|
-
|
|
84
|
+
before : typing.Optional[str]
|
|
85
|
+
Cursor for pagination
|
|
86
|
+
|
|
87
|
+
after : typing.Optional[str]
|
|
87
88
|
Cursor for pagination
|
|
88
89
|
|
|
89
90
|
limit : typing.Optional[int]
|
|
@@ -116,7 +117,8 @@ class AgentsClient:
|
|
|
116
117
|
"name": name,
|
|
117
118
|
"tags": tags,
|
|
118
119
|
"match_all_tags": match_all_tags,
|
|
119
|
-
"
|
|
120
|
+
"before": before,
|
|
121
|
+
"after": after,
|
|
120
122
|
"limit": limit,
|
|
121
123
|
"query_text": query_text,
|
|
122
124
|
},
|
|
@@ -600,23 +602,29 @@ class AgentsClient:
|
|
|
600
602
|
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
601
603
|
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
602
604
|
|
|
603
|
-
def
|
|
604
|
-
self,
|
|
605
|
-
|
|
605
|
+
def reset_messages(
|
|
606
|
+
self,
|
|
607
|
+
agent_id: str,
|
|
608
|
+
*,
|
|
609
|
+
add_default_initial_messages: typing.Optional[bool] = None,
|
|
610
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
611
|
+
) -> AgentState:
|
|
606
612
|
"""
|
|
607
|
-
|
|
608
|
-
This endpoint fetches the current memory state of the agent identified by the user ID and agent ID.
|
|
613
|
+
Resets the messages for an agent
|
|
609
614
|
|
|
610
615
|
Parameters
|
|
611
616
|
----------
|
|
612
617
|
agent_id : str
|
|
613
618
|
|
|
619
|
+
add_default_initial_messages : typing.Optional[bool]
|
|
620
|
+
If true, adds the default initial messages after resetting.
|
|
621
|
+
|
|
614
622
|
request_options : typing.Optional[RequestOptions]
|
|
615
623
|
Request-specific configuration.
|
|
616
624
|
|
|
617
625
|
Returns
|
|
618
626
|
-------
|
|
619
|
-
|
|
627
|
+
AgentState
|
|
620
628
|
Successful Response
|
|
621
629
|
|
|
622
630
|
Examples
|
|
@@ -626,21 +634,24 @@ class AgentsClient:
|
|
|
626
634
|
client = Letta(
|
|
627
635
|
token="YOUR_TOKEN",
|
|
628
636
|
)
|
|
629
|
-
client.agents.
|
|
637
|
+
client.agents.reset_messages(
|
|
630
638
|
agent_id="agent_id",
|
|
631
639
|
)
|
|
632
640
|
"""
|
|
633
641
|
_response = self._client_wrapper.httpx_client.request(
|
|
634
|
-
f"v1/agents/{jsonable_encoder(agent_id)}/
|
|
635
|
-
method="
|
|
642
|
+
f"v1/agents/{jsonable_encoder(agent_id)}/reset-messages",
|
|
643
|
+
method="PATCH",
|
|
644
|
+
params={
|
|
645
|
+
"add_default_initial_messages": add_default_initial_messages,
|
|
646
|
+
},
|
|
636
647
|
request_options=request_options,
|
|
637
648
|
)
|
|
638
649
|
try:
|
|
639
650
|
if 200 <= _response.status_code < 300:
|
|
640
651
|
return typing.cast(
|
|
641
|
-
|
|
652
|
+
AgentState,
|
|
642
653
|
construct_type(
|
|
643
|
-
type_=
|
|
654
|
+
type_=AgentState, # type: ignore
|
|
644
655
|
object_=_response.json(),
|
|
645
656
|
),
|
|
646
657
|
)
|
|
@@ -659,25 +670,39 @@ class AgentsClient:
|
|
|
659
670
|
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
660
671
|
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
661
672
|
|
|
662
|
-
def
|
|
663
|
-
self,
|
|
664
|
-
|
|
673
|
+
def search(
|
|
674
|
+
self,
|
|
675
|
+
*,
|
|
676
|
+
search: typing.Optional[typing.Sequence[AgentsSearchRequestSearchItem]] = OMIT,
|
|
677
|
+
project_id: typing.Optional[str] = OMIT,
|
|
678
|
+
combinator: typing.Optional[AgentsSearchRequestCombinator] = OMIT,
|
|
679
|
+
limit: typing.Optional[float] = OMIT,
|
|
680
|
+
offset: typing.Optional[float] = OMIT,
|
|
681
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
682
|
+
) -> None:
|
|
665
683
|
"""
|
|
666
|
-
|
|
684
|
+
<Note>This endpoint is only available on Letta Cloud.</Note>
|
|
685
|
+
|
|
686
|
+
Search deployed agents.
|
|
667
687
|
|
|
668
688
|
Parameters
|
|
669
689
|
----------
|
|
670
|
-
|
|
690
|
+
search : typing.Optional[typing.Sequence[AgentsSearchRequestSearchItem]]
|
|
691
|
+
|
|
692
|
+
project_id : typing.Optional[str]
|
|
693
|
+
|
|
694
|
+
combinator : typing.Optional[AgentsSearchRequestCombinator]
|
|
695
|
+
|
|
696
|
+
limit : typing.Optional[float]
|
|
671
697
|
|
|
672
|
-
|
|
698
|
+
offset : typing.Optional[float]
|
|
673
699
|
|
|
674
700
|
request_options : typing.Optional[RequestOptions]
|
|
675
701
|
Request-specific configuration.
|
|
676
702
|
|
|
677
703
|
Returns
|
|
678
704
|
-------
|
|
679
|
-
|
|
680
|
-
Successful Response
|
|
705
|
+
None
|
|
681
706
|
|
|
682
707
|
Examples
|
|
683
708
|
--------
|
|
@@ -686,183 +711,131 @@ class AgentsClient:
|
|
|
686
711
|
client = Letta(
|
|
687
712
|
token="YOUR_TOKEN",
|
|
688
713
|
)
|
|
689
|
-
client.agents.
|
|
690
|
-
agent_id="agent_id",
|
|
691
|
-
block_label="block_label",
|
|
692
|
-
)
|
|
714
|
+
client.agents.search()
|
|
693
715
|
"""
|
|
694
716
|
_response = self._client_wrapper.httpx_client.request(
|
|
695
|
-
|
|
696
|
-
method="
|
|
717
|
+
"v1/agents/search",
|
|
718
|
+
method="POST",
|
|
719
|
+
json={
|
|
720
|
+
"search": convert_and_respect_annotation_metadata(
|
|
721
|
+
object_=search, annotation=typing.Sequence[AgentsSearchRequestSearchItem], direction="write"
|
|
722
|
+
),
|
|
723
|
+
"project_id": project_id,
|
|
724
|
+
"combinator": combinator,
|
|
725
|
+
"limit": limit,
|
|
726
|
+
"offset": offset,
|
|
727
|
+
},
|
|
728
|
+
headers={
|
|
729
|
+
"content-type": "application/json",
|
|
730
|
+
},
|
|
697
731
|
request_options=request_options,
|
|
732
|
+
omit=OMIT,
|
|
698
733
|
)
|
|
699
734
|
try:
|
|
700
735
|
if 200 <= _response.status_code < 300:
|
|
701
|
-
return
|
|
702
|
-
Block,
|
|
703
|
-
construct_type(
|
|
704
|
-
type_=Block, # type: ignore
|
|
705
|
-
object_=_response.json(),
|
|
706
|
-
),
|
|
707
|
-
)
|
|
708
|
-
if _response.status_code == 422:
|
|
709
|
-
raise UnprocessableEntityError(
|
|
710
|
-
typing.cast(
|
|
711
|
-
HttpValidationError,
|
|
712
|
-
construct_type(
|
|
713
|
-
type_=HttpValidationError, # type: ignore
|
|
714
|
-
object_=_response.json(),
|
|
715
|
-
),
|
|
716
|
-
)
|
|
717
|
-
)
|
|
736
|
+
return
|
|
718
737
|
_response_json = _response.json()
|
|
719
738
|
except JSONDecodeError:
|
|
720
739
|
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
721
740
|
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
722
741
|
|
|
723
|
-
|
|
742
|
+
|
|
743
|
+
class AsyncAgentsClient:
|
|
744
|
+
def __init__(self, *, client_wrapper: AsyncClientWrapper):
|
|
745
|
+
self._client_wrapper = client_wrapper
|
|
746
|
+
self.context = AsyncContextClient(client_wrapper=self._client_wrapper)
|
|
747
|
+
self.tools = AsyncToolsClient(client_wrapper=self._client_wrapper)
|
|
748
|
+
self.sources = AsyncSourcesClient(client_wrapper=self._client_wrapper)
|
|
749
|
+
self.core_memory = AsyncCoreMemoryClient(client_wrapper=self._client_wrapper)
|
|
750
|
+
self.archival_memory = AsyncArchivalMemoryClient(client_wrapper=self._client_wrapper)
|
|
751
|
+
self.messages = AsyncMessagesClient(client_wrapper=self._client_wrapper)
|
|
752
|
+
self.templates = AsyncTemplatesClient(client_wrapper=self._client_wrapper)
|
|
753
|
+
self.memory_variables = AsyncMemoryVariablesClient(client_wrapper=self._client_wrapper)
|
|
754
|
+
|
|
755
|
+
async def list(
|
|
724
756
|
self,
|
|
725
|
-
agent_id: str,
|
|
726
|
-
block_label: str,
|
|
727
757
|
*,
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
758
|
+
name: typing.Optional[str] = None,
|
|
759
|
+
tags: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
|
|
760
|
+
match_all_tags: typing.Optional[bool] = None,
|
|
761
|
+
before: typing.Optional[str] = None,
|
|
762
|
+
after: typing.Optional[str] = None,
|
|
763
|
+
limit: typing.Optional[int] = None,
|
|
764
|
+
query_text: typing.Optional[str] = None,
|
|
735
765
|
request_options: typing.Optional[RequestOptions] = None,
|
|
736
|
-
) ->
|
|
766
|
+
) -> typing.List[AgentState]:
|
|
737
767
|
"""
|
|
738
|
-
|
|
768
|
+
List all agents associated with a given user.
|
|
769
|
+
This endpoint retrieves a list of all agents and their configurations associated with the specified user ID.
|
|
739
770
|
|
|
740
771
|
Parameters
|
|
741
772
|
----------
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
block_label : str
|
|
745
|
-
|
|
746
|
-
value : typing.Optional[str]
|
|
747
|
-
Value of the block.
|
|
773
|
+
name : typing.Optional[str]
|
|
774
|
+
Name of the agent
|
|
748
775
|
|
|
749
|
-
|
|
750
|
-
|
|
776
|
+
tags : typing.Optional[typing.Union[str, typing.Sequence[str]]]
|
|
777
|
+
List of tags to filter agents by
|
|
751
778
|
|
|
752
|
-
|
|
753
|
-
|
|
779
|
+
match_all_tags : typing.Optional[bool]
|
|
780
|
+
If True, only returns agents that match ALL given tags. Otherwise, return agents that have ANY of the passed in tags.
|
|
754
781
|
|
|
755
|
-
|
|
756
|
-
|
|
782
|
+
before : typing.Optional[str]
|
|
783
|
+
Cursor for pagination
|
|
757
784
|
|
|
758
|
-
|
|
759
|
-
|
|
785
|
+
after : typing.Optional[str]
|
|
786
|
+
Cursor for pagination
|
|
760
787
|
|
|
761
|
-
|
|
762
|
-
|
|
788
|
+
limit : typing.Optional[int]
|
|
789
|
+
Limit for pagination
|
|
763
790
|
|
|
764
|
-
|
|
765
|
-
|
|
791
|
+
query_text : typing.Optional[str]
|
|
792
|
+
Search agents by name
|
|
766
793
|
|
|
767
794
|
request_options : typing.Optional[RequestOptions]
|
|
768
795
|
Request-specific configuration.
|
|
769
796
|
|
|
770
797
|
Returns
|
|
771
798
|
-------
|
|
772
|
-
|
|
799
|
+
typing.List[AgentState]
|
|
773
800
|
Successful Response
|
|
774
801
|
|
|
775
802
|
Examples
|
|
776
803
|
--------
|
|
777
|
-
|
|
804
|
+
import asyncio
|
|
778
805
|
|
|
779
|
-
|
|
806
|
+
from letta_client import AsyncLetta
|
|
807
|
+
|
|
808
|
+
client = AsyncLetta(
|
|
780
809
|
token="YOUR_TOKEN",
|
|
781
810
|
)
|
|
782
|
-
client.agents.modify_core_memory_block(
|
|
783
|
-
agent_id="agent_id",
|
|
784
|
-
block_label="block_label",
|
|
785
|
-
)
|
|
786
|
-
"""
|
|
787
|
-
_response = self._client_wrapper.httpx_client.request(
|
|
788
|
-
f"v1/agents/{jsonable_encoder(agent_id)}/core-memory/blocks/{jsonable_encoder(block_label)}",
|
|
789
|
-
method="PATCH",
|
|
790
|
-
json={
|
|
791
|
-
"value": value,
|
|
792
|
-
"limit": limit,
|
|
793
|
-
"name": name,
|
|
794
|
-
"is_template": is_template,
|
|
795
|
-
"label": label,
|
|
796
|
-
"description": description,
|
|
797
|
-
"metadata": metadata,
|
|
798
|
-
},
|
|
799
|
-
request_options=request_options,
|
|
800
|
-
omit=OMIT,
|
|
801
|
-
)
|
|
802
|
-
try:
|
|
803
|
-
if 200 <= _response.status_code < 300:
|
|
804
|
-
return typing.cast(
|
|
805
|
-
Block,
|
|
806
|
-
construct_type(
|
|
807
|
-
type_=Block, # type: ignore
|
|
808
|
-
object_=_response.json(),
|
|
809
|
-
),
|
|
810
|
-
)
|
|
811
|
-
if _response.status_code == 422:
|
|
812
|
-
raise UnprocessableEntityError(
|
|
813
|
-
typing.cast(
|
|
814
|
-
HttpValidationError,
|
|
815
|
-
construct_type(
|
|
816
|
-
type_=HttpValidationError, # type: ignore
|
|
817
|
-
object_=_response.json(),
|
|
818
|
-
),
|
|
819
|
-
)
|
|
820
|
-
)
|
|
821
|
-
_response_json = _response.json()
|
|
822
|
-
except JSONDecodeError:
|
|
823
|
-
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
824
|
-
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
825
811
|
|
|
826
|
-
def list_core_memory_blocks(
|
|
827
|
-
self, agent_id: str, *, request_options: typing.Optional[RequestOptions] = None
|
|
828
|
-
) -> typing.List[Block]:
|
|
829
|
-
"""
|
|
830
|
-
Retrieve the memory blocks of a specific agent.
|
|
831
|
-
|
|
832
|
-
Parameters
|
|
833
|
-
----------
|
|
834
|
-
agent_id : str
|
|
835
|
-
|
|
836
|
-
request_options : typing.Optional[RequestOptions]
|
|
837
|
-
Request-specific configuration.
|
|
838
812
|
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
typing.List[Block]
|
|
842
|
-
Successful Response
|
|
813
|
+
async def main() -> None:
|
|
814
|
+
await client.agents.list()
|
|
843
815
|
|
|
844
|
-
Examples
|
|
845
|
-
--------
|
|
846
|
-
from letta_client import Letta
|
|
847
816
|
|
|
848
|
-
|
|
849
|
-
token="YOUR_TOKEN",
|
|
850
|
-
)
|
|
851
|
-
client.agents.list_core_memory_blocks(
|
|
852
|
-
agent_id="agent_id",
|
|
853
|
-
)
|
|
817
|
+
asyncio.run(main())
|
|
854
818
|
"""
|
|
855
|
-
_response = self._client_wrapper.httpx_client.request(
|
|
856
|
-
|
|
819
|
+
_response = await self._client_wrapper.httpx_client.request(
|
|
820
|
+
"v1/agents/",
|
|
857
821
|
method="GET",
|
|
822
|
+
params={
|
|
823
|
+
"name": name,
|
|
824
|
+
"tags": tags,
|
|
825
|
+
"match_all_tags": match_all_tags,
|
|
826
|
+
"before": before,
|
|
827
|
+
"after": after,
|
|
828
|
+
"limit": limit,
|
|
829
|
+
"query_text": query_text,
|
|
830
|
+
},
|
|
858
831
|
request_options=request_options,
|
|
859
832
|
)
|
|
860
833
|
try:
|
|
861
834
|
if 200 <= _response.status_code < 300:
|
|
862
835
|
return typing.cast(
|
|
863
|
-
typing.List[
|
|
836
|
+
typing.List[AgentState],
|
|
864
837
|
construct_type(
|
|
865
|
-
type_=typing.List[
|
|
838
|
+
type_=typing.List[AgentState], # type: ignore
|
|
866
839
|
object_=_response.json(),
|
|
867
840
|
),
|
|
868
841
|
)
|
|
@@ -881,1393 +854,119 @@ class AgentsClient:
|
|
|
881
854
|
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
882
855
|
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
883
856
|
|
|
884
|
-
def
|
|
885
|
-
self,
|
|
857
|
+
async def create(
|
|
858
|
+
self,
|
|
859
|
+
*,
|
|
860
|
+
name: typing.Optional[str] = OMIT,
|
|
861
|
+
memory_blocks: typing.Optional[typing.Sequence[CreateBlock]] = OMIT,
|
|
862
|
+
tools: typing.Optional[typing.Sequence[str]] = OMIT,
|
|
863
|
+
tool_ids: typing.Optional[typing.Sequence[str]] = OMIT,
|
|
864
|
+
source_ids: typing.Optional[typing.Sequence[str]] = OMIT,
|
|
865
|
+
block_ids: typing.Optional[typing.Sequence[str]] = OMIT,
|
|
866
|
+
tool_rules: typing.Optional[typing.Sequence[CreateAgentRequestToolRulesItem]] = OMIT,
|
|
867
|
+
tags: typing.Optional[typing.Sequence[str]] = OMIT,
|
|
868
|
+
system: typing.Optional[str] = OMIT,
|
|
869
|
+
agent_type: typing.Optional[AgentType] = OMIT,
|
|
870
|
+
llm_config: typing.Optional[LlmConfig] = OMIT,
|
|
871
|
+
embedding_config: typing.Optional[EmbeddingConfig] = OMIT,
|
|
872
|
+
initial_message_sequence: typing.Optional[typing.Sequence[MessageCreate]] = OMIT,
|
|
873
|
+
include_base_tools: typing.Optional[bool] = OMIT,
|
|
874
|
+
include_multi_agent_tools: typing.Optional[bool] = OMIT,
|
|
875
|
+
description: typing.Optional[str] = OMIT,
|
|
876
|
+
metadata: typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] = OMIT,
|
|
877
|
+
model: typing.Optional[str] = OMIT,
|
|
878
|
+
embedding: typing.Optional[str] = OMIT,
|
|
879
|
+
context_window_limit: typing.Optional[int] = OMIT,
|
|
880
|
+
embedding_chunk_size: typing.Optional[int] = OMIT,
|
|
881
|
+
from_template: typing.Optional[str] = OMIT,
|
|
882
|
+
template: typing.Optional[bool] = OMIT,
|
|
883
|
+
project: typing.Optional[str] = OMIT,
|
|
884
|
+
tool_exec_environment_variables: typing.Optional[typing.Dict[str, typing.Optional[str]]] = OMIT,
|
|
885
|
+
memory_variables: typing.Optional[typing.Dict[str, typing.Optional[str]]] = OMIT,
|
|
886
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
886
887
|
) -> AgentState:
|
|
887
888
|
"""
|
|
888
|
-
|
|
889
|
+
Create a new agent with the specified configuration.
|
|
889
890
|
|
|
890
891
|
Parameters
|
|
891
892
|
----------
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
block_id : str
|
|
893
|
+
name : typing.Optional[str]
|
|
894
|
+
The name of the agent.
|
|
895
895
|
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
Returns
|
|
900
|
-
-------
|
|
901
|
-
AgentState
|
|
902
|
-
Successful Response
|
|
903
|
-
|
|
904
|
-
Examples
|
|
905
|
-
--------
|
|
906
|
-
from letta_client import Letta
|
|
907
|
-
|
|
908
|
-
client = Letta(
|
|
909
|
-
token="YOUR_TOKEN",
|
|
910
|
-
)
|
|
911
|
-
client.agents.attach_core_memory_block(
|
|
912
|
-
agent_id="agent_id",
|
|
913
|
-
block_id="block_id",
|
|
914
|
-
)
|
|
915
|
-
"""
|
|
916
|
-
_response = self._client_wrapper.httpx_client.request(
|
|
917
|
-
f"v1/agents/{jsonable_encoder(agent_id)}/core-memory/blocks/attach/{jsonable_encoder(block_id)}",
|
|
918
|
-
method="PATCH",
|
|
919
|
-
request_options=request_options,
|
|
920
|
-
)
|
|
921
|
-
try:
|
|
922
|
-
if 200 <= _response.status_code < 300:
|
|
923
|
-
return typing.cast(
|
|
924
|
-
AgentState,
|
|
925
|
-
construct_type(
|
|
926
|
-
type_=AgentState, # type: ignore
|
|
927
|
-
object_=_response.json(),
|
|
928
|
-
),
|
|
929
|
-
)
|
|
930
|
-
if _response.status_code == 422:
|
|
931
|
-
raise UnprocessableEntityError(
|
|
932
|
-
typing.cast(
|
|
933
|
-
HttpValidationError,
|
|
934
|
-
construct_type(
|
|
935
|
-
type_=HttpValidationError, # type: ignore
|
|
936
|
-
object_=_response.json(),
|
|
937
|
-
),
|
|
938
|
-
)
|
|
939
|
-
)
|
|
940
|
-
_response_json = _response.json()
|
|
941
|
-
except JSONDecodeError:
|
|
942
|
-
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
943
|
-
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
944
|
-
|
|
945
|
-
def detach_core_memory_block(
|
|
946
|
-
self, agent_id: str, block_id: str, *, request_options: typing.Optional[RequestOptions] = None
|
|
947
|
-
) -> AgentState:
|
|
948
|
-
"""
|
|
949
|
-
Detach a block from an agent.
|
|
950
|
-
|
|
951
|
-
Parameters
|
|
952
|
-
----------
|
|
953
|
-
agent_id : str
|
|
954
|
-
|
|
955
|
-
block_id : str
|
|
956
|
-
|
|
957
|
-
request_options : typing.Optional[RequestOptions]
|
|
958
|
-
Request-specific configuration.
|
|
959
|
-
|
|
960
|
-
Returns
|
|
961
|
-
-------
|
|
962
|
-
AgentState
|
|
963
|
-
Successful Response
|
|
964
|
-
|
|
965
|
-
Examples
|
|
966
|
-
--------
|
|
967
|
-
from letta_client import Letta
|
|
968
|
-
|
|
969
|
-
client = Letta(
|
|
970
|
-
token="YOUR_TOKEN",
|
|
971
|
-
)
|
|
972
|
-
client.agents.detach_core_memory_block(
|
|
973
|
-
agent_id="agent_id",
|
|
974
|
-
block_id="block_id",
|
|
975
|
-
)
|
|
976
|
-
"""
|
|
977
|
-
_response = self._client_wrapper.httpx_client.request(
|
|
978
|
-
f"v1/agents/{jsonable_encoder(agent_id)}/core-memory/blocks/detach/{jsonable_encoder(block_id)}",
|
|
979
|
-
method="PATCH",
|
|
980
|
-
request_options=request_options,
|
|
981
|
-
)
|
|
982
|
-
try:
|
|
983
|
-
if 200 <= _response.status_code < 300:
|
|
984
|
-
return typing.cast(
|
|
985
|
-
AgentState,
|
|
986
|
-
construct_type(
|
|
987
|
-
type_=AgentState, # type: ignore
|
|
988
|
-
object_=_response.json(),
|
|
989
|
-
),
|
|
990
|
-
)
|
|
991
|
-
if _response.status_code == 422:
|
|
992
|
-
raise UnprocessableEntityError(
|
|
993
|
-
typing.cast(
|
|
994
|
-
HttpValidationError,
|
|
995
|
-
construct_type(
|
|
996
|
-
type_=HttpValidationError, # type: ignore
|
|
997
|
-
object_=_response.json(),
|
|
998
|
-
),
|
|
999
|
-
)
|
|
1000
|
-
)
|
|
1001
|
-
_response_json = _response.json()
|
|
1002
|
-
except JSONDecodeError:
|
|
1003
|
-
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
1004
|
-
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
1005
|
-
|
|
1006
|
-
def list_archival_memory(
|
|
1007
|
-
self,
|
|
1008
|
-
agent_id: str,
|
|
1009
|
-
*,
|
|
1010
|
-
after: typing.Optional[int] = None,
|
|
1011
|
-
before: typing.Optional[int] = None,
|
|
1012
|
-
limit: typing.Optional[int] = None,
|
|
1013
|
-
request_options: typing.Optional[RequestOptions] = None,
|
|
1014
|
-
) -> typing.List[Passage]:
|
|
1015
|
-
"""
|
|
1016
|
-
Retrieve the memories in an agent's archival memory store (paginated query).
|
|
1017
|
-
|
|
1018
|
-
Parameters
|
|
1019
|
-
----------
|
|
1020
|
-
agent_id : str
|
|
1021
|
-
|
|
1022
|
-
after : typing.Optional[int]
|
|
1023
|
-
Unique ID of the memory to start the query range at.
|
|
1024
|
-
|
|
1025
|
-
before : typing.Optional[int]
|
|
1026
|
-
Unique ID of the memory to end the query range at.
|
|
1027
|
-
|
|
1028
|
-
limit : typing.Optional[int]
|
|
1029
|
-
How many results to include in the response.
|
|
1030
|
-
|
|
1031
|
-
request_options : typing.Optional[RequestOptions]
|
|
1032
|
-
Request-specific configuration.
|
|
1033
|
-
|
|
1034
|
-
Returns
|
|
1035
|
-
-------
|
|
1036
|
-
typing.List[Passage]
|
|
1037
|
-
Successful Response
|
|
1038
|
-
|
|
1039
|
-
Examples
|
|
1040
|
-
--------
|
|
1041
|
-
from letta_client import Letta
|
|
1042
|
-
|
|
1043
|
-
client = Letta(
|
|
1044
|
-
token="YOUR_TOKEN",
|
|
1045
|
-
)
|
|
1046
|
-
client.agents.list_archival_memory(
|
|
1047
|
-
agent_id="agent_id",
|
|
1048
|
-
)
|
|
1049
|
-
"""
|
|
1050
|
-
_response = self._client_wrapper.httpx_client.request(
|
|
1051
|
-
f"v1/agents/{jsonable_encoder(agent_id)}/archival-memory",
|
|
1052
|
-
method="GET",
|
|
1053
|
-
params={
|
|
1054
|
-
"after": after,
|
|
1055
|
-
"before": before,
|
|
1056
|
-
"limit": limit,
|
|
1057
|
-
},
|
|
1058
|
-
request_options=request_options,
|
|
1059
|
-
)
|
|
1060
|
-
try:
|
|
1061
|
-
if 200 <= _response.status_code < 300:
|
|
1062
|
-
return typing.cast(
|
|
1063
|
-
typing.List[Passage],
|
|
1064
|
-
construct_type(
|
|
1065
|
-
type_=typing.List[Passage], # type: ignore
|
|
1066
|
-
object_=_response.json(),
|
|
1067
|
-
),
|
|
1068
|
-
)
|
|
1069
|
-
if _response.status_code == 422:
|
|
1070
|
-
raise UnprocessableEntityError(
|
|
1071
|
-
typing.cast(
|
|
1072
|
-
HttpValidationError,
|
|
1073
|
-
construct_type(
|
|
1074
|
-
type_=HttpValidationError, # type: ignore
|
|
1075
|
-
object_=_response.json(),
|
|
1076
|
-
),
|
|
1077
|
-
)
|
|
1078
|
-
)
|
|
1079
|
-
_response_json = _response.json()
|
|
1080
|
-
except JSONDecodeError:
|
|
1081
|
-
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
1082
|
-
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
1083
|
-
|
|
1084
|
-
def create_archival_memory(
|
|
1085
|
-
self, agent_id: str, *, text: str, request_options: typing.Optional[RequestOptions] = None
|
|
1086
|
-
) -> typing.List[Passage]:
|
|
1087
|
-
"""
|
|
1088
|
-
Insert a memory into an agent's archival memory store.
|
|
1089
|
-
|
|
1090
|
-
Parameters
|
|
1091
|
-
----------
|
|
1092
|
-
agent_id : str
|
|
1093
|
-
|
|
1094
|
-
text : str
|
|
1095
|
-
Text to write to archival memory.
|
|
1096
|
-
|
|
1097
|
-
request_options : typing.Optional[RequestOptions]
|
|
1098
|
-
Request-specific configuration.
|
|
1099
|
-
|
|
1100
|
-
Returns
|
|
1101
|
-
-------
|
|
1102
|
-
typing.List[Passage]
|
|
1103
|
-
Successful Response
|
|
1104
|
-
|
|
1105
|
-
Examples
|
|
1106
|
-
--------
|
|
1107
|
-
from letta_client import Letta
|
|
1108
|
-
|
|
1109
|
-
client = Letta(
|
|
1110
|
-
token="YOUR_TOKEN",
|
|
1111
|
-
)
|
|
1112
|
-
client.agents.create_archival_memory(
|
|
1113
|
-
agent_id="agent_id",
|
|
1114
|
-
text="text",
|
|
1115
|
-
)
|
|
1116
|
-
"""
|
|
1117
|
-
_response = self._client_wrapper.httpx_client.request(
|
|
1118
|
-
f"v1/agents/{jsonable_encoder(agent_id)}/archival-memory",
|
|
1119
|
-
method="POST",
|
|
1120
|
-
json={
|
|
1121
|
-
"text": text,
|
|
1122
|
-
},
|
|
1123
|
-
headers={
|
|
1124
|
-
"content-type": "application/json",
|
|
1125
|
-
},
|
|
1126
|
-
request_options=request_options,
|
|
1127
|
-
omit=OMIT,
|
|
1128
|
-
)
|
|
1129
|
-
try:
|
|
1130
|
-
if 200 <= _response.status_code < 300:
|
|
1131
|
-
return typing.cast(
|
|
1132
|
-
typing.List[Passage],
|
|
1133
|
-
construct_type(
|
|
1134
|
-
type_=typing.List[Passage], # type: ignore
|
|
1135
|
-
object_=_response.json(),
|
|
1136
|
-
),
|
|
1137
|
-
)
|
|
1138
|
-
if _response.status_code == 422:
|
|
1139
|
-
raise UnprocessableEntityError(
|
|
1140
|
-
typing.cast(
|
|
1141
|
-
HttpValidationError,
|
|
1142
|
-
construct_type(
|
|
1143
|
-
type_=HttpValidationError, # type: ignore
|
|
1144
|
-
object_=_response.json(),
|
|
1145
|
-
),
|
|
1146
|
-
)
|
|
1147
|
-
)
|
|
1148
|
-
_response_json = _response.json()
|
|
1149
|
-
except JSONDecodeError:
|
|
1150
|
-
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
1151
|
-
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
1152
|
-
|
|
1153
|
-
def delete_archival_memory(
|
|
1154
|
-
self, agent_id: str, memory_id: str, *, request_options: typing.Optional[RequestOptions] = None
|
|
1155
|
-
) -> typing.Optional[typing.Any]:
|
|
1156
|
-
"""
|
|
1157
|
-
Delete a memory from an agent's archival memory store.
|
|
1158
|
-
|
|
1159
|
-
Parameters
|
|
1160
|
-
----------
|
|
1161
|
-
agent_id : str
|
|
1162
|
-
|
|
1163
|
-
memory_id : str
|
|
1164
|
-
|
|
1165
|
-
request_options : typing.Optional[RequestOptions]
|
|
1166
|
-
Request-specific configuration.
|
|
1167
|
-
|
|
1168
|
-
Returns
|
|
1169
|
-
-------
|
|
1170
|
-
typing.Optional[typing.Any]
|
|
1171
|
-
Successful Response
|
|
1172
|
-
|
|
1173
|
-
Examples
|
|
1174
|
-
--------
|
|
1175
|
-
from letta_client import Letta
|
|
1176
|
-
|
|
1177
|
-
client = Letta(
|
|
1178
|
-
token="YOUR_TOKEN",
|
|
1179
|
-
)
|
|
1180
|
-
client.agents.delete_archival_memory(
|
|
1181
|
-
agent_id="agent_id",
|
|
1182
|
-
memory_id="memory_id",
|
|
1183
|
-
)
|
|
1184
|
-
"""
|
|
1185
|
-
_response = self._client_wrapper.httpx_client.request(
|
|
1186
|
-
f"v1/agents/{jsonable_encoder(agent_id)}/archival-memory/{jsonable_encoder(memory_id)}",
|
|
1187
|
-
method="DELETE",
|
|
1188
|
-
request_options=request_options,
|
|
1189
|
-
)
|
|
1190
|
-
try:
|
|
1191
|
-
if 200 <= _response.status_code < 300:
|
|
1192
|
-
return typing.cast(
|
|
1193
|
-
typing.Optional[typing.Any],
|
|
1194
|
-
construct_type(
|
|
1195
|
-
type_=typing.Optional[typing.Any], # type: ignore
|
|
1196
|
-
object_=_response.json(),
|
|
1197
|
-
),
|
|
1198
|
-
)
|
|
1199
|
-
if _response.status_code == 422:
|
|
1200
|
-
raise UnprocessableEntityError(
|
|
1201
|
-
typing.cast(
|
|
1202
|
-
HttpValidationError,
|
|
1203
|
-
construct_type(
|
|
1204
|
-
type_=HttpValidationError, # type: ignore
|
|
1205
|
-
object_=_response.json(),
|
|
1206
|
-
),
|
|
1207
|
-
)
|
|
1208
|
-
)
|
|
1209
|
-
_response_json = _response.json()
|
|
1210
|
-
except JSONDecodeError:
|
|
1211
|
-
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
1212
|
-
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
1213
|
-
|
|
1214
|
-
def reset_messages(
|
|
1215
|
-
self,
|
|
1216
|
-
agent_id: str,
|
|
1217
|
-
*,
|
|
1218
|
-
add_default_initial_messages: typing.Optional[bool] = None,
|
|
1219
|
-
request_options: typing.Optional[RequestOptions] = None,
|
|
1220
|
-
) -> AgentState:
|
|
1221
|
-
"""
|
|
1222
|
-
Resets the messages for an agent
|
|
1223
|
-
|
|
1224
|
-
Parameters
|
|
1225
|
-
----------
|
|
1226
|
-
agent_id : str
|
|
1227
|
-
|
|
1228
|
-
add_default_initial_messages : typing.Optional[bool]
|
|
1229
|
-
If true, adds the default initial messages after resetting.
|
|
1230
|
-
|
|
1231
|
-
request_options : typing.Optional[RequestOptions]
|
|
1232
|
-
Request-specific configuration.
|
|
1233
|
-
|
|
1234
|
-
Returns
|
|
1235
|
-
-------
|
|
1236
|
-
AgentState
|
|
1237
|
-
Successful Response
|
|
1238
|
-
|
|
1239
|
-
Examples
|
|
1240
|
-
--------
|
|
1241
|
-
from letta_client import Letta
|
|
1242
|
-
|
|
1243
|
-
client = Letta(
|
|
1244
|
-
token="YOUR_TOKEN",
|
|
1245
|
-
)
|
|
1246
|
-
client.agents.reset_messages(
|
|
1247
|
-
agent_id="agent_id",
|
|
1248
|
-
)
|
|
1249
|
-
"""
|
|
1250
|
-
_response = self._client_wrapper.httpx_client.request(
|
|
1251
|
-
f"v1/agents/{jsonable_encoder(agent_id)}/reset-messages",
|
|
1252
|
-
method="PATCH",
|
|
1253
|
-
params={
|
|
1254
|
-
"add_default_initial_messages": add_default_initial_messages,
|
|
1255
|
-
},
|
|
1256
|
-
request_options=request_options,
|
|
1257
|
-
)
|
|
1258
|
-
try:
|
|
1259
|
-
if 200 <= _response.status_code < 300:
|
|
1260
|
-
return typing.cast(
|
|
1261
|
-
AgentState,
|
|
1262
|
-
construct_type(
|
|
1263
|
-
type_=AgentState, # type: ignore
|
|
1264
|
-
object_=_response.json(),
|
|
1265
|
-
),
|
|
1266
|
-
)
|
|
1267
|
-
if _response.status_code == 422:
|
|
1268
|
-
raise UnprocessableEntityError(
|
|
1269
|
-
typing.cast(
|
|
1270
|
-
HttpValidationError,
|
|
1271
|
-
construct_type(
|
|
1272
|
-
type_=HttpValidationError, # type: ignore
|
|
1273
|
-
object_=_response.json(),
|
|
1274
|
-
),
|
|
1275
|
-
)
|
|
1276
|
-
)
|
|
1277
|
-
_response_json = _response.json()
|
|
1278
|
-
except JSONDecodeError:
|
|
1279
|
-
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
1280
|
-
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
1281
|
-
|
|
1282
|
-
def search(
|
|
1283
|
-
self,
|
|
1284
|
-
*,
|
|
1285
|
-
search: typing.Optional[typing.Sequence[AgentsSearchRequestSearchItem]] = OMIT,
|
|
1286
|
-
project_id: typing.Optional[str] = OMIT,
|
|
1287
|
-
combinator: typing.Optional[AgentsSearchRequestCombinator] = OMIT,
|
|
1288
|
-
limit: typing.Optional[float] = OMIT,
|
|
1289
|
-
offset: typing.Optional[float] = OMIT,
|
|
1290
|
-
request_options: typing.Optional[RequestOptions] = None,
|
|
1291
|
-
) -> None:
|
|
1292
|
-
"""
|
|
1293
|
-
<Note>This endpoint is only available on Letta Cloud.</Note>
|
|
1294
|
-
|
|
1295
|
-
Search deployed agents.
|
|
1296
|
-
|
|
1297
|
-
Parameters
|
|
1298
|
-
----------
|
|
1299
|
-
search : typing.Optional[typing.Sequence[AgentsSearchRequestSearchItem]]
|
|
1300
|
-
|
|
1301
|
-
project_id : typing.Optional[str]
|
|
1302
|
-
|
|
1303
|
-
combinator : typing.Optional[AgentsSearchRequestCombinator]
|
|
1304
|
-
|
|
1305
|
-
limit : typing.Optional[float]
|
|
1306
|
-
|
|
1307
|
-
offset : typing.Optional[float]
|
|
1308
|
-
|
|
1309
|
-
request_options : typing.Optional[RequestOptions]
|
|
1310
|
-
Request-specific configuration.
|
|
1311
|
-
|
|
1312
|
-
Returns
|
|
1313
|
-
-------
|
|
1314
|
-
None
|
|
1315
|
-
|
|
1316
|
-
Examples
|
|
1317
|
-
--------
|
|
1318
|
-
from letta_client import Letta
|
|
1319
|
-
|
|
1320
|
-
client = Letta(
|
|
1321
|
-
token="YOUR_TOKEN",
|
|
1322
|
-
)
|
|
1323
|
-
client.agents.search()
|
|
1324
|
-
"""
|
|
1325
|
-
_response = self._client_wrapper.httpx_client.request(
|
|
1326
|
-
"v1/agents/search",
|
|
1327
|
-
method="POST",
|
|
1328
|
-
json={
|
|
1329
|
-
"search": convert_and_respect_annotation_metadata(
|
|
1330
|
-
object_=search, annotation=typing.Sequence[AgentsSearchRequestSearchItem], direction="write"
|
|
1331
|
-
),
|
|
1332
|
-
"project_id": project_id,
|
|
1333
|
-
"combinator": combinator,
|
|
1334
|
-
"limit": limit,
|
|
1335
|
-
"offset": offset,
|
|
1336
|
-
},
|
|
1337
|
-
headers={
|
|
1338
|
-
"content-type": "application/json",
|
|
1339
|
-
},
|
|
1340
|
-
request_options=request_options,
|
|
1341
|
-
omit=OMIT,
|
|
1342
|
-
)
|
|
1343
|
-
try:
|
|
1344
|
-
if 200 <= _response.status_code < 300:
|
|
1345
|
-
return
|
|
1346
|
-
_response_json = _response.json()
|
|
1347
|
-
except JSONDecodeError:
|
|
1348
|
-
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
1349
|
-
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
class AsyncAgentsClient:
|
|
1353
|
-
def __init__(self, *, client_wrapper: AsyncClientWrapper):
|
|
1354
|
-
self._client_wrapper = client_wrapper
|
|
1355
|
-
self.context = AsyncContextClient(client_wrapper=self._client_wrapper)
|
|
1356
|
-
self.tools = AsyncToolsClient(client_wrapper=self._client_wrapper)
|
|
1357
|
-
self.sources = AsyncSourcesClient(client_wrapper=self._client_wrapper)
|
|
1358
|
-
self.messages = AsyncMessagesClient(client_wrapper=self._client_wrapper)
|
|
1359
|
-
self.templates = AsyncTemplatesClient(client_wrapper=self._client_wrapper)
|
|
1360
|
-
self.memory_variables = AsyncMemoryVariablesClient(client_wrapper=self._client_wrapper)
|
|
1361
|
-
self.core_memory = AsyncCoreMemoryClient(client_wrapper=self._client_wrapper)
|
|
1362
|
-
self.archival_memory = AsyncArchivalMemoryClient(client_wrapper=self._client_wrapper)
|
|
1363
|
-
|
|
1364
|
-
async def list(
|
|
1365
|
-
self,
|
|
1366
|
-
*,
|
|
1367
|
-
name: typing.Optional[str] = None,
|
|
1368
|
-
tags: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
|
|
1369
|
-
match_all_tags: typing.Optional[bool] = None,
|
|
1370
|
-
cursor: typing.Optional[str] = None,
|
|
1371
|
-
limit: typing.Optional[int] = None,
|
|
1372
|
-
query_text: typing.Optional[str] = None,
|
|
1373
|
-
request_options: typing.Optional[RequestOptions] = None,
|
|
1374
|
-
) -> typing.List[AgentState]:
|
|
1375
|
-
"""
|
|
1376
|
-
List all agents associated with a given user.
|
|
1377
|
-
This endpoint retrieves a list of all agents and their configurations associated with the specified user ID.
|
|
1378
|
-
|
|
1379
|
-
Parameters
|
|
1380
|
-
----------
|
|
1381
|
-
name : typing.Optional[str]
|
|
1382
|
-
Name of the agent
|
|
1383
|
-
|
|
1384
|
-
tags : typing.Optional[typing.Union[str, typing.Sequence[str]]]
|
|
1385
|
-
List of tags to filter agents by
|
|
1386
|
-
|
|
1387
|
-
match_all_tags : typing.Optional[bool]
|
|
1388
|
-
If True, only returns agents that match ALL given tags. Otherwise, return agents that have ANY of the passed in tags.
|
|
1389
|
-
|
|
1390
|
-
cursor : typing.Optional[str]
|
|
1391
|
-
Cursor for pagination
|
|
1392
|
-
|
|
1393
|
-
limit : typing.Optional[int]
|
|
1394
|
-
Limit for pagination
|
|
1395
|
-
|
|
1396
|
-
query_text : typing.Optional[str]
|
|
1397
|
-
Search agents by name
|
|
1398
|
-
|
|
1399
|
-
request_options : typing.Optional[RequestOptions]
|
|
1400
|
-
Request-specific configuration.
|
|
1401
|
-
|
|
1402
|
-
Returns
|
|
1403
|
-
-------
|
|
1404
|
-
typing.List[AgentState]
|
|
1405
|
-
Successful Response
|
|
1406
|
-
|
|
1407
|
-
Examples
|
|
1408
|
-
--------
|
|
1409
|
-
import asyncio
|
|
1410
|
-
|
|
1411
|
-
from letta_client import AsyncLetta
|
|
1412
|
-
|
|
1413
|
-
client = AsyncLetta(
|
|
1414
|
-
token="YOUR_TOKEN",
|
|
1415
|
-
)
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
async def main() -> None:
|
|
1419
|
-
await client.agents.list()
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
asyncio.run(main())
|
|
1423
|
-
"""
|
|
1424
|
-
_response = await self._client_wrapper.httpx_client.request(
|
|
1425
|
-
"v1/agents/",
|
|
1426
|
-
method="GET",
|
|
1427
|
-
params={
|
|
1428
|
-
"name": name,
|
|
1429
|
-
"tags": tags,
|
|
1430
|
-
"match_all_tags": match_all_tags,
|
|
1431
|
-
"cursor": cursor,
|
|
1432
|
-
"limit": limit,
|
|
1433
|
-
"query_text": query_text,
|
|
1434
|
-
},
|
|
1435
|
-
request_options=request_options,
|
|
1436
|
-
)
|
|
1437
|
-
try:
|
|
1438
|
-
if 200 <= _response.status_code < 300:
|
|
1439
|
-
return typing.cast(
|
|
1440
|
-
typing.List[AgentState],
|
|
1441
|
-
construct_type(
|
|
1442
|
-
type_=typing.List[AgentState], # type: ignore
|
|
1443
|
-
object_=_response.json(),
|
|
1444
|
-
),
|
|
1445
|
-
)
|
|
1446
|
-
if _response.status_code == 422:
|
|
1447
|
-
raise UnprocessableEntityError(
|
|
1448
|
-
typing.cast(
|
|
1449
|
-
HttpValidationError,
|
|
1450
|
-
construct_type(
|
|
1451
|
-
type_=HttpValidationError, # type: ignore
|
|
1452
|
-
object_=_response.json(),
|
|
1453
|
-
),
|
|
1454
|
-
)
|
|
1455
|
-
)
|
|
1456
|
-
_response_json = _response.json()
|
|
1457
|
-
except JSONDecodeError:
|
|
1458
|
-
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
1459
|
-
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
1460
|
-
|
|
1461
|
-
async def create(
|
|
1462
|
-
self,
|
|
1463
|
-
*,
|
|
1464
|
-
name: typing.Optional[str] = OMIT,
|
|
1465
|
-
memory_blocks: typing.Optional[typing.Sequence[CreateBlock]] = OMIT,
|
|
1466
|
-
tools: typing.Optional[typing.Sequence[str]] = OMIT,
|
|
1467
|
-
tool_ids: typing.Optional[typing.Sequence[str]] = OMIT,
|
|
1468
|
-
source_ids: typing.Optional[typing.Sequence[str]] = OMIT,
|
|
1469
|
-
block_ids: typing.Optional[typing.Sequence[str]] = OMIT,
|
|
1470
|
-
tool_rules: typing.Optional[typing.Sequence[CreateAgentRequestToolRulesItem]] = OMIT,
|
|
1471
|
-
tags: typing.Optional[typing.Sequence[str]] = OMIT,
|
|
1472
|
-
system: typing.Optional[str] = OMIT,
|
|
1473
|
-
agent_type: typing.Optional[AgentType] = OMIT,
|
|
1474
|
-
llm_config: typing.Optional[LlmConfig] = OMIT,
|
|
1475
|
-
embedding_config: typing.Optional[EmbeddingConfig] = OMIT,
|
|
1476
|
-
initial_message_sequence: typing.Optional[typing.Sequence[MessageCreate]] = OMIT,
|
|
1477
|
-
include_base_tools: typing.Optional[bool] = OMIT,
|
|
1478
|
-
include_multi_agent_tools: typing.Optional[bool] = OMIT,
|
|
1479
|
-
description: typing.Optional[str] = OMIT,
|
|
1480
|
-
metadata: typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] = OMIT,
|
|
1481
|
-
model: typing.Optional[str] = OMIT,
|
|
1482
|
-
embedding: typing.Optional[str] = OMIT,
|
|
1483
|
-
context_window_limit: typing.Optional[int] = OMIT,
|
|
1484
|
-
embedding_chunk_size: typing.Optional[int] = OMIT,
|
|
1485
|
-
from_template: typing.Optional[str] = OMIT,
|
|
1486
|
-
template: typing.Optional[bool] = OMIT,
|
|
1487
|
-
project: typing.Optional[str] = OMIT,
|
|
1488
|
-
tool_exec_environment_variables: typing.Optional[typing.Dict[str, typing.Optional[str]]] = OMIT,
|
|
1489
|
-
memory_variables: typing.Optional[typing.Dict[str, typing.Optional[str]]] = OMIT,
|
|
1490
|
-
request_options: typing.Optional[RequestOptions] = None,
|
|
1491
|
-
) -> AgentState:
|
|
1492
|
-
"""
|
|
1493
|
-
Create a new agent with the specified configuration.
|
|
1494
|
-
|
|
1495
|
-
Parameters
|
|
1496
|
-
----------
|
|
1497
|
-
name : typing.Optional[str]
|
|
1498
|
-
The name of the agent.
|
|
1499
|
-
|
|
1500
|
-
memory_blocks : typing.Optional[typing.Sequence[CreateBlock]]
|
|
1501
|
-
The blocks to create in the agent's in-context memory.
|
|
1502
|
-
|
|
1503
|
-
tools : typing.Optional[typing.Sequence[str]]
|
|
1504
|
-
The tools used by the agent.
|
|
1505
|
-
|
|
1506
|
-
tool_ids : typing.Optional[typing.Sequence[str]]
|
|
1507
|
-
The ids of the tools used by the agent.
|
|
1508
|
-
|
|
1509
|
-
source_ids : typing.Optional[typing.Sequence[str]]
|
|
1510
|
-
The ids of the sources used by the agent.
|
|
1511
|
-
|
|
1512
|
-
block_ids : typing.Optional[typing.Sequence[str]]
|
|
1513
|
-
The ids of the blocks used by the agent.
|
|
1514
|
-
|
|
1515
|
-
tool_rules : typing.Optional[typing.Sequence[CreateAgentRequestToolRulesItem]]
|
|
1516
|
-
The tool rules governing the agent.
|
|
1517
|
-
|
|
1518
|
-
tags : typing.Optional[typing.Sequence[str]]
|
|
1519
|
-
The tags associated with the agent.
|
|
1520
|
-
|
|
1521
|
-
system : typing.Optional[str]
|
|
1522
|
-
The system prompt used by the agent.
|
|
1523
|
-
|
|
1524
|
-
agent_type : typing.Optional[AgentType]
|
|
1525
|
-
The type of agent.
|
|
1526
|
-
|
|
1527
|
-
llm_config : typing.Optional[LlmConfig]
|
|
1528
|
-
The LLM configuration used by the agent.
|
|
1529
|
-
|
|
1530
|
-
embedding_config : typing.Optional[EmbeddingConfig]
|
|
1531
|
-
The embedding configuration used by the agent.
|
|
1532
|
-
|
|
1533
|
-
initial_message_sequence : typing.Optional[typing.Sequence[MessageCreate]]
|
|
1534
|
-
The initial set of messages to put in the agent's in-context memory.
|
|
1535
|
-
|
|
1536
|
-
include_base_tools : typing.Optional[bool]
|
|
1537
|
-
If true, attaches the Letta core tools (e.g. archival_memory and core_memory related functions).
|
|
1538
|
-
|
|
1539
|
-
include_multi_agent_tools : typing.Optional[bool]
|
|
1540
|
-
If true, attaches the Letta multi-agent tools (e.g. sending a message to another agent).
|
|
1541
|
-
|
|
1542
|
-
description : typing.Optional[str]
|
|
1543
|
-
The description of the agent.
|
|
1544
|
-
|
|
1545
|
-
metadata : typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]]
|
|
1546
|
-
The metadata of the agent.
|
|
1547
|
-
|
|
1548
|
-
model : typing.Optional[str]
|
|
1549
|
-
The LLM configuration handle used by the agent, specified in the format provider/model-name, as an alternative to specifying llm_config.
|
|
1550
|
-
|
|
1551
|
-
embedding : typing.Optional[str]
|
|
1552
|
-
The embedding configuration handle used by the agent, specified in the format provider/model-name.
|
|
1553
|
-
|
|
1554
|
-
context_window_limit : typing.Optional[int]
|
|
1555
|
-
The context window limit used by the agent.
|
|
1556
|
-
|
|
1557
|
-
embedding_chunk_size : typing.Optional[int]
|
|
1558
|
-
The embedding chunk size used by the agent.
|
|
1559
|
-
|
|
1560
|
-
from_template : typing.Optional[str]
|
|
1561
|
-
The template id used to configure the agent
|
|
1562
|
-
|
|
1563
|
-
template : typing.Optional[bool]
|
|
1564
|
-
Whether the agent is a template
|
|
1565
|
-
|
|
1566
|
-
project : typing.Optional[str]
|
|
1567
|
-
The project slug that the agent will be associated with.
|
|
1568
|
-
|
|
1569
|
-
tool_exec_environment_variables : typing.Optional[typing.Dict[str, typing.Optional[str]]]
|
|
1570
|
-
The environment variables for tool execution specific to this agent.
|
|
1571
|
-
|
|
1572
|
-
memory_variables : typing.Optional[typing.Dict[str, typing.Optional[str]]]
|
|
1573
|
-
The variables that should be set for the agent.
|
|
1574
|
-
|
|
1575
|
-
request_options : typing.Optional[RequestOptions]
|
|
1576
|
-
Request-specific configuration.
|
|
1577
|
-
|
|
1578
|
-
Returns
|
|
1579
|
-
-------
|
|
1580
|
-
AgentState
|
|
1581
|
-
Successful Response
|
|
1582
|
-
|
|
1583
|
-
Examples
|
|
1584
|
-
--------
|
|
1585
|
-
import asyncio
|
|
1586
|
-
|
|
1587
|
-
from letta_client import AsyncLetta
|
|
1588
|
-
|
|
1589
|
-
client = AsyncLetta(
|
|
1590
|
-
token="YOUR_TOKEN",
|
|
1591
|
-
)
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
async def main() -> None:
|
|
1595
|
-
await client.agents.create()
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
asyncio.run(main())
|
|
1599
|
-
"""
|
|
1600
|
-
_response = await self._client_wrapper.httpx_client.request(
|
|
1601
|
-
"v1/agents/",
|
|
1602
|
-
method="POST",
|
|
1603
|
-
json={
|
|
1604
|
-
"name": name,
|
|
1605
|
-
"memory_blocks": convert_and_respect_annotation_metadata(
|
|
1606
|
-
object_=memory_blocks, annotation=typing.Sequence[CreateBlock], direction="write"
|
|
1607
|
-
),
|
|
1608
|
-
"tools": tools,
|
|
1609
|
-
"tool_ids": tool_ids,
|
|
1610
|
-
"source_ids": source_ids,
|
|
1611
|
-
"block_ids": block_ids,
|
|
1612
|
-
"tool_rules": convert_and_respect_annotation_metadata(
|
|
1613
|
-
object_=tool_rules, annotation=typing.Sequence[CreateAgentRequestToolRulesItem], direction="write"
|
|
1614
|
-
),
|
|
1615
|
-
"tags": tags,
|
|
1616
|
-
"system": system,
|
|
1617
|
-
"agent_type": agent_type,
|
|
1618
|
-
"llm_config": convert_and_respect_annotation_metadata(
|
|
1619
|
-
object_=llm_config, annotation=LlmConfig, direction="write"
|
|
1620
|
-
),
|
|
1621
|
-
"embedding_config": convert_and_respect_annotation_metadata(
|
|
1622
|
-
object_=embedding_config, annotation=EmbeddingConfig, direction="write"
|
|
1623
|
-
),
|
|
1624
|
-
"initial_message_sequence": convert_and_respect_annotation_metadata(
|
|
1625
|
-
object_=initial_message_sequence, annotation=typing.Sequence[MessageCreate], direction="write"
|
|
1626
|
-
),
|
|
1627
|
-
"include_base_tools": include_base_tools,
|
|
1628
|
-
"include_multi_agent_tools": include_multi_agent_tools,
|
|
1629
|
-
"description": description,
|
|
1630
|
-
"metadata": metadata,
|
|
1631
|
-
"model": model,
|
|
1632
|
-
"embedding": embedding,
|
|
1633
|
-
"context_window_limit": context_window_limit,
|
|
1634
|
-
"embedding_chunk_size": embedding_chunk_size,
|
|
1635
|
-
"from_template": from_template,
|
|
1636
|
-
"template": template,
|
|
1637
|
-
"project": project,
|
|
1638
|
-
"tool_exec_environment_variables": tool_exec_environment_variables,
|
|
1639
|
-
"memory_variables": memory_variables,
|
|
1640
|
-
},
|
|
1641
|
-
headers={
|
|
1642
|
-
"content-type": "application/json",
|
|
1643
|
-
},
|
|
1644
|
-
request_options=request_options,
|
|
1645
|
-
omit=OMIT,
|
|
1646
|
-
)
|
|
1647
|
-
try:
|
|
1648
|
-
if 200 <= _response.status_code < 300:
|
|
1649
|
-
return typing.cast(
|
|
1650
|
-
AgentState,
|
|
1651
|
-
construct_type(
|
|
1652
|
-
type_=AgentState, # type: ignore
|
|
1653
|
-
object_=_response.json(),
|
|
1654
|
-
),
|
|
1655
|
-
)
|
|
1656
|
-
if _response.status_code == 422:
|
|
1657
|
-
raise UnprocessableEntityError(
|
|
1658
|
-
typing.cast(
|
|
1659
|
-
HttpValidationError,
|
|
1660
|
-
construct_type(
|
|
1661
|
-
type_=HttpValidationError, # type: ignore
|
|
1662
|
-
object_=_response.json(),
|
|
1663
|
-
),
|
|
1664
|
-
)
|
|
1665
|
-
)
|
|
1666
|
-
_response_json = _response.json()
|
|
1667
|
-
except JSONDecodeError:
|
|
1668
|
-
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
1669
|
-
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
1670
|
-
|
|
1671
|
-
async def retrieve(self, agent_id: str, *, request_options: typing.Optional[RequestOptions] = None) -> AgentState:
|
|
1672
|
-
"""
|
|
1673
|
-
Get the state of the agent.
|
|
1674
|
-
|
|
1675
|
-
Parameters
|
|
1676
|
-
----------
|
|
1677
|
-
agent_id : str
|
|
1678
|
-
|
|
1679
|
-
request_options : typing.Optional[RequestOptions]
|
|
1680
|
-
Request-specific configuration.
|
|
1681
|
-
|
|
1682
|
-
Returns
|
|
1683
|
-
-------
|
|
1684
|
-
AgentState
|
|
1685
|
-
Successful Response
|
|
1686
|
-
|
|
1687
|
-
Examples
|
|
1688
|
-
--------
|
|
1689
|
-
import asyncio
|
|
1690
|
-
|
|
1691
|
-
from letta_client import AsyncLetta
|
|
1692
|
-
|
|
1693
|
-
client = AsyncLetta(
|
|
1694
|
-
token="YOUR_TOKEN",
|
|
1695
|
-
)
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
async def main() -> None:
|
|
1699
|
-
await client.agents.retrieve(
|
|
1700
|
-
agent_id="agent_id",
|
|
1701
|
-
)
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
asyncio.run(main())
|
|
1705
|
-
"""
|
|
1706
|
-
_response = await self._client_wrapper.httpx_client.request(
|
|
1707
|
-
f"v1/agents/{jsonable_encoder(agent_id)}",
|
|
1708
|
-
method="GET",
|
|
1709
|
-
request_options=request_options,
|
|
1710
|
-
)
|
|
1711
|
-
try:
|
|
1712
|
-
if 200 <= _response.status_code < 300:
|
|
1713
|
-
return typing.cast(
|
|
1714
|
-
AgentState,
|
|
1715
|
-
construct_type(
|
|
1716
|
-
type_=AgentState, # type: ignore
|
|
1717
|
-
object_=_response.json(),
|
|
1718
|
-
),
|
|
1719
|
-
)
|
|
1720
|
-
if _response.status_code == 422:
|
|
1721
|
-
raise UnprocessableEntityError(
|
|
1722
|
-
typing.cast(
|
|
1723
|
-
HttpValidationError,
|
|
1724
|
-
construct_type(
|
|
1725
|
-
type_=HttpValidationError, # type: ignore
|
|
1726
|
-
object_=_response.json(),
|
|
1727
|
-
),
|
|
1728
|
-
)
|
|
1729
|
-
)
|
|
1730
|
-
_response_json = _response.json()
|
|
1731
|
-
except JSONDecodeError:
|
|
1732
|
-
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
1733
|
-
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
1734
|
-
|
|
1735
|
-
async def delete(
|
|
1736
|
-
self, agent_id: str, *, request_options: typing.Optional[RequestOptions] = None
|
|
1737
|
-
) -> typing.Optional[typing.Any]:
|
|
1738
|
-
"""
|
|
1739
|
-
Delete an agent.
|
|
1740
|
-
|
|
1741
|
-
Parameters
|
|
1742
|
-
----------
|
|
1743
|
-
agent_id : str
|
|
1744
|
-
|
|
1745
|
-
request_options : typing.Optional[RequestOptions]
|
|
1746
|
-
Request-specific configuration.
|
|
1747
|
-
|
|
1748
|
-
Returns
|
|
1749
|
-
-------
|
|
1750
|
-
typing.Optional[typing.Any]
|
|
1751
|
-
Successful Response
|
|
1752
|
-
|
|
1753
|
-
Examples
|
|
1754
|
-
--------
|
|
1755
|
-
import asyncio
|
|
1756
|
-
|
|
1757
|
-
from letta_client import AsyncLetta
|
|
1758
|
-
|
|
1759
|
-
client = AsyncLetta(
|
|
1760
|
-
token="YOUR_TOKEN",
|
|
1761
|
-
)
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
async def main() -> None:
|
|
1765
|
-
await client.agents.delete(
|
|
1766
|
-
agent_id="agent_id",
|
|
1767
|
-
)
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
asyncio.run(main())
|
|
1771
|
-
"""
|
|
1772
|
-
_response = await self._client_wrapper.httpx_client.request(
|
|
1773
|
-
f"v1/agents/{jsonable_encoder(agent_id)}",
|
|
1774
|
-
method="DELETE",
|
|
1775
|
-
request_options=request_options,
|
|
1776
|
-
)
|
|
1777
|
-
try:
|
|
1778
|
-
if 200 <= _response.status_code < 300:
|
|
1779
|
-
return typing.cast(
|
|
1780
|
-
typing.Optional[typing.Any],
|
|
1781
|
-
construct_type(
|
|
1782
|
-
type_=typing.Optional[typing.Any], # type: ignore
|
|
1783
|
-
object_=_response.json(),
|
|
1784
|
-
),
|
|
1785
|
-
)
|
|
1786
|
-
if _response.status_code == 422:
|
|
1787
|
-
raise UnprocessableEntityError(
|
|
1788
|
-
typing.cast(
|
|
1789
|
-
HttpValidationError,
|
|
1790
|
-
construct_type(
|
|
1791
|
-
type_=HttpValidationError, # type: ignore
|
|
1792
|
-
object_=_response.json(),
|
|
1793
|
-
),
|
|
1794
|
-
)
|
|
1795
|
-
)
|
|
1796
|
-
_response_json = _response.json()
|
|
1797
|
-
except JSONDecodeError:
|
|
1798
|
-
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
1799
|
-
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
1800
|
-
|
|
1801
|
-
async def modify(
|
|
1802
|
-
self,
|
|
1803
|
-
agent_id: str,
|
|
1804
|
-
*,
|
|
1805
|
-
name: typing.Optional[str] = OMIT,
|
|
1806
|
-
tool_ids: typing.Optional[typing.Sequence[str]] = OMIT,
|
|
1807
|
-
source_ids: typing.Optional[typing.Sequence[str]] = OMIT,
|
|
1808
|
-
block_ids: typing.Optional[typing.Sequence[str]] = OMIT,
|
|
1809
|
-
tags: typing.Optional[typing.Sequence[str]] = OMIT,
|
|
1810
|
-
system: typing.Optional[str] = OMIT,
|
|
1811
|
-
tool_rules: typing.Optional[typing.Sequence[UpdateAgentToolRulesItem]] = OMIT,
|
|
1812
|
-
llm_config: typing.Optional[LlmConfig] = OMIT,
|
|
1813
|
-
embedding_config: typing.Optional[EmbeddingConfig] = OMIT,
|
|
1814
|
-
message_ids: typing.Optional[typing.Sequence[str]] = OMIT,
|
|
1815
|
-
description: typing.Optional[str] = OMIT,
|
|
1816
|
-
metadata: typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] = OMIT,
|
|
1817
|
-
tool_exec_environment_variables: typing.Optional[typing.Dict[str, typing.Optional[str]]] = OMIT,
|
|
1818
|
-
request_options: typing.Optional[RequestOptions] = None,
|
|
1819
|
-
) -> AgentState:
|
|
1820
|
-
"""
|
|
1821
|
-
Update an existing agent
|
|
1822
|
-
|
|
1823
|
-
Parameters
|
|
1824
|
-
----------
|
|
1825
|
-
agent_id : str
|
|
1826
|
-
|
|
1827
|
-
name : typing.Optional[str]
|
|
1828
|
-
The name of the agent.
|
|
1829
|
-
|
|
1830
|
-
tool_ids : typing.Optional[typing.Sequence[str]]
|
|
1831
|
-
The ids of the tools used by the agent.
|
|
1832
|
-
|
|
1833
|
-
source_ids : typing.Optional[typing.Sequence[str]]
|
|
1834
|
-
The ids of the sources used by the agent.
|
|
1835
|
-
|
|
1836
|
-
block_ids : typing.Optional[typing.Sequence[str]]
|
|
1837
|
-
The ids of the blocks used by the agent.
|
|
1838
|
-
|
|
1839
|
-
tags : typing.Optional[typing.Sequence[str]]
|
|
1840
|
-
The tags associated with the agent.
|
|
1841
|
-
|
|
1842
|
-
system : typing.Optional[str]
|
|
1843
|
-
The system prompt used by the agent.
|
|
1844
|
-
|
|
1845
|
-
tool_rules : typing.Optional[typing.Sequence[UpdateAgentToolRulesItem]]
|
|
1846
|
-
The tool rules governing the agent.
|
|
1847
|
-
|
|
1848
|
-
llm_config : typing.Optional[LlmConfig]
|
|
1849
|
-
The LLM configuration used by the agent.
|
|
1850
|
-
|
|
1851
|
-
embedding_config : typing.Optional[EmbeddingConfig]
|
|
1852
|
-
The embedding configuration used by the agent.
|
|
1853
|
-
|
|
1854
|
-
message_ids : typing.Optional[typing.Sequence[str]]
|
|
1855
|
-
The ids of the messages in the agent's in-context memory.
|
|
1856
|
-
|
|
1857
|
-
description : typing.Optional[str]
|
|
1858
|
-
The description of the agent.
|
|
1859
|
-
|
|
1860
|
-
metadata : typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]]
|
|
1861
|
-
The metadata of the agent.
|
|
1862
|
-
|
|
1863
|
-
tool_exec_environment_variables : typing.Optional[typing.Dict[str, typing.Optional[str]]]
|
|
1864
|
-
The environment variables for tool execution specific to this agent.
|
|
1865
|
-
|
|
1866
|
-
request_options : typing.Optional[RequestOptions]
|
|
1867
|
-
Request-specific configuration.
|
|
1868
|
-
|
|
1869
|
-
Returns
|
|
1870
|
-
-------
|
|
1871
|
-
AgentState
|
|
1872
|
-
Successful Response
|
|
1873
|
-
|
|
1874
|
-
Examples
|
|
1875
|
-
--------
|
|
1876
|
-
import asyncio
|
|
1877
|
-
|
|
1878
|
-
from letta_client import AsyncLetta
|
|
1879
|
-
|
|
1880
|
-
client = AsyncLetta(
|
|
1881
|
-
token="YOUR_TOKEN",
|
|
1882
|
-
)
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
async def main() -> None:
|
|
1886
|
-
await client.agents.modify(
|
|
1887
|
-
agent_id="agent_id",
|
|
1888
|
-
)
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
asyncio.run(main())
|
|
1892
|
-
"""
|
|
1893
|
-
_response = await self._client_wrapper.httpx_client.request(
|
|
1894
|
-
f"v1/agents/{jsonable_encoder(agent_id)}",
|
|
1895
|
-
method="PATCH",
|
|
1896
|
-
json={
|
|
1897
|
-
"name": name,
|
|
1898
|
-
"tool_ids": tool_ids,
|
|
1899
|
-
"source_ids": source_ids,
|
|
1900
|
-
"block_ids": block_ids,
|
|
1901
|
-
"tags": tags,
|
|
1902
|
-
"system": system,
|
|
1903
|
-
"tool_rules": convert_and_respect_annotation_metadata(
|
|
1904
|
-
object_=tool_rules, annotation=typing.Sequence[UpdateAgentToolRulesItem], direction="write"
|
|
1905
|
-
),
|
|
1906
|
-
"llm_config": convert_and_respect_annotation_metadata(
|
|
1907
|
-
object_=llm_config, annotation=LlmConfig, direction="write"
|
|
1908
|
-
),
|
|
1909
|
-
"embedding_config": convert_and_respect_annotation_metadata(
|
|
1910
|
-
object_=embedding_config, annotation=EmbeddingConfig, direction="write"
|
|
1911
|
-
),
|
|
1912
|
-
"message_ids": message_ids,
|
|
1913
|
-
"description": description,
|
|
1914
|
-
"metadata": metadata,
|
|
1915
|
-
"tool_exec_environment_variables": tool_exec_environment_variables,
|
|
1916
|
-
},
|
|
1917
|
-
headers={
|
|
1918
|
-
"content-type": "application/json",
|
|
1919
|
-
},
|
|
1920
|
-
request_options=request_options,
|
|
1921
|
-
omit=OMIT,
|
|
1922
|
-
)
|
|
1923
|
-
try:
|
|
1924
|
-
if 200 <= _response.status_code < 300:
|
|
1925
|
-
return typing.cast(
|
|
1926
|
-
AgentState,
|
|
1927
|
-
construct_type(
|
|
1928
|
-
type_=AgentState, # type: ignore
|
|
1929
|
-
object_=_response.json(),
|
|
1930
|
-
),
|
|
1931
|
-
)
|
|
1932
|
-
if _response.status_code == 422:
|
|
1933
|
-
raise UnprocessableEntityError(
|
|
1934
|
-
typing.cast(
|
|
1935
|
-
HttpValidationError,
|
|
1936
|
-
construct_type(
|
|
1937
|
-
type_=HttpValidationError, # type: ignore
|
|
1938
|
-
object_=_response.json(),
|
|
1939
|
-
),
|
|
1940
|
-
)
|
|
1941
|
-
)
|
|
1942
|
-
_response_json = _response.json()
|
|
1943
|
-
except JSONDecodeError:
|
|
1944
|
-
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
1945
|
-
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
1946
|
-
|
|
1947
|
-
async def retrieve_agent_memory(
|
|
1948
|
-
self, agent_id: str, *, request_options: typing.Optional[RequestOptions] = None
|
|
1949
|
-
) -> Memory:
|
|
1950
|
-
"""
|
|
1951
|
-
Retrieve the memory state of a specific agent.
|
|
1952
|
-
This endpoint fetches the current memory state of the agent identified by the user ID and agent ID.
|
|
1953
|
-
|
|
1954
|
-
Parameters
|
|
1955
|
-
----------
|
|
1956
|
-
agent_id : str
|
|
1957
|
-
|
|
1958
|
-
request_options : typing.Optional[RequestOptions]
|
|
1959
|
-
Request-specific configuration.
|
|
1960
|
-
|
|
1961
|
-
Returns
|
|
1962
|
-
-------
|
|
1963
|
-
Memory
|
|
1964
|
-
Successful Response
|
|
1965
|
-
|
|
1966
|
-
Examples
|
|
1967
|
-
--------
|
|
1968
|
-
import asyncio
|
|
1969
|
-
|
|
1970
|
-
from letta_client import AsyncLetta
|
|
1971
|
-
|
|
1972
|
-
client = AsyncLetta(
|
|
1973
|
-
token="YOUR_TOKEN",
|
|
1974
|
-
)
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
async def main() -> None:
|
|
1978
|
-
await client.agents.retrieve_agent_memory(
|
|
1979
|
-
agent_id="agent_id",
|
|
1980
|
-
)
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
asyncio.run(main())
|
|
1984
|
-
"""
|
|
1985
|
-
_response = await self._client_wrapper.httpx_client.request(
|
|
1986
|
-
f"v1/agents/{jsonable_encoder(agent_id)}/core-memory",
|
|
1987
|
-
method="GET",
|
|
1988
|
-
request_options=request_options,
|
|
1989
|
-
)
|
|
1990
|
-
try:
|
|
1991
|
-
if 200 <= _response.status_code < 300:
|
|
1992
|
-
return typing.cast(
|
|
1993
|
-
Memory,
|
|
1994
|
-
construct_type(
|
|
1995
|
-
type_=Memory, # type: ignore
|
|
1996
|
-
object_=_response.json(),
|
|
1997
|
-
),
|
|
1998
|
-
)
|
|
1999
|
-
if _response.status_code == 422:
|
|
2000
|
-
raise UnprocessableEntityError(
|
|
2001
|
-
typing.cast(
|
|
2002
|
-
HttpValidationError,
|
|
2003
|
-
construct_type(
|
|
2004
|
-
type_=HttpValidationError, # type: ignore
|
|
2005
|
-
object_=_response.json(),
|
|
2006
|
-
),
|
|
2007
|
-
)
|
|
2008
|
-
)
|
|
2009
|
-
_response_json = _response.json()
|
|
2010
|
-
except JSONDecodeError:
|
|
2011
|
-
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
2012
|
-
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
2013
|
-
|
|
2014
|
-
async def retrieve_core_memory_block(
|
|
2015
|
-
self, agent_id: str, block_label: str, *, request_options: typing.Optional[RequestOptions] = None
|
|
2016
|
-
) -> Block:
|
|
2017
|
-
"""
|
|
2018
|
-
Retrieve a memory block from an agent.
|
|
2019
|
-
|
|
2020
|
-
Parameters
|
|
2021
|
-
----------
|
|
2022
|
-
agent_id : str
|
|
2023
|
-
|
|
2024
|
-
block_label : str
|
|
2025
|
-
|
|
2026
|
-
request_options : typing.Optional[RequestOptions]
|
|
2027
|
-
Request-specific configuration.
|
|
2028
|
-
|
|
2029
|
-
Returns
|
|
2030
|
-
-------
|
|
2031
|
-
Block
|
|
2032
|
-
Successful Response
|
|
2033
|
-
|
|
2034
|
-
Examples
|
|
2035
|
-
--------
|
|
2036
|
-
import asyncio
|
|
2037
|
-
|
|
2038
|
-
from letta_client import AsyncLetta
|
|
896
|
+
memory_blocks : typing.Optional[typing.Sequence[CreateBlock]]
|
|
897
|
+
The blocks to create in the agent's in-context memory.
|
|
2039
898
|
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
)
|
|
899
|
+
tools : typing.Optional[typing.Sequence[str]]
|
|
900
|
+
The tools used by the agent.
|
|
2043
901
|
|
|
902
|
+
tool_ids : typing.Optional[typing.Sequence[str]]
|
|
903
|
+
The ids of the tools used by the agent.
|
|
2044
904
|
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
agent_id="agent_id",
|
|
2048
|
-
block_label="block_label",
|
|
2049
|
-
)
|
|
905
|
+
source_ids : typing.Optional[typing.Sequence[str]]
|
|
906
|
+
The ids of the sources used by the agent.
|
|
2050
907
|
|
|
908
|
+
block_ids : typing.Optional[typing.Sequence[str]]
|
|
909
|
+
The ids of the blocks used by the agent.
|
|
2051
910
|
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
_response = await self._client_wrapper.httpx_client.request(
|
|
2055
|
-
f"v1/agents/{jsonable_encoder(agent_id)}/core-memory/blocks/{jsonable_encoder(block_label)}",
|
|
2056
|
-
method="GET",
|
|
2057
|
-
request_options=request_options,
|
|
2058
|
-
)
|
|
2059
|
-
try:
|
|
2060
|
-
if 200 <= _response.status_code < 300:
|
|
2061
|
-
return typing.cast(
|
|
2062
|
-
Block,
|
|
2063
|
-
construct_type(
|
|
2064
|
-
type_=Block, # type: ignore
|
|
2065
|
-
object_=_response.json(),
|
|
2066
|
-
),
|
|
2067
|
-
)
|
|
2068
|
-
if _response.status_code == 422:
|
|
2069
|
-
raise UnprocessableEntityError(
|
|
2070
|
-
typing.cast(
|
|
2071
|
-
HttpValidationError,
|
|
2072
|
-
construct_type(
|
|
2073
|
-
type_=HttpValidationError, # type: ignore
|
|
2074
|
-
object_=_response.json(),
|
|
2075
|
-
),
|
|
2076
|
-
)
|
|
2077
|
-
)
|
|
2078
|
-
_response_json = _response.json()
|
|
2079
|
-
except JSONDecodeError:
|
|
2080
|
-
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
2081
|
-
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
911
|
+
tool_rules : typing.Optional[typing.Sequence[CreateAgentRequestToolRulesItem]]
|
|
912
|
+
The tool rules governing the agent.
|
|
2082
913
|
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
agent_id: str,
|
|
2086
|
-
block_label: str,
|
|
2087
|
-
*,
|
|
2088
|
-
value: typing.Optional[str] = OMIT,
|
|
2089
|
-
limit: typing.Optional[int] = OMIT,
|
|
2090
|
-
name: typing.Optional[str] = OMIT,
|
|
2091
|
-
is_template: typing.Optional[bool] = OMIT,
|
|
2092
|
-
label: typing.Optional[str] = OMIT,
|
|
2093
|
-
description: typing.Optional[str] = OMIT,
|
|
2094
|
-
metadata: typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] = OMIT,
|
|
2095
|
-
request_options: typing.Optional[RequestOptions] = None,
|
|
2096
|
-
) -> Block:
|
|
2097
|
-
"""
|
|
2098
|
-
Updates a memory block of an agent.
|
|
914
|
+
tags : typing.Optional[typing.Sequence[str]]
|
|
915
|
+
The tags associated with the agent.
|
|
2099
916
|
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
agent_id : str
|
|
917
|
+
system : typing.Optional[str]
|
|
918
|
+
The system prompt used by the agent.
|
|
2103
919
|
|
|
2104
|
-
|
|
920
|
+
agent_type : typing.Optional[AgentType]
|
|
921
|
+
The type of agent.
|
|
2105
922
|
|
|
2106
|
-
|
|
2107
|
-
|
|
923
|
+
llm_config : typing.Optional[LlmConfig]
|
|
924
|
+
The LLM configuration used by the agent.
|
|
2108
925
|
|
|
2109
|
-
|
|
2110
|
-
|
|
926
|
+
embedding_config : typing.Optional[EmbeddingConfig]
|
|
927
|
+
The embedding configuration used by the agent.
|
|
2111
928
|
|
|
2112
|
-
|
|
2113
|
-
|
|
929
|
+
initial_message_sequence : typing.Optional[typing.Sequence[MessageCreate]]
|
|
930
|
+
The initial set of messages to put in the agent's in-context memory.
|
|
2114
931
|
|
|
2115
|
-
|
|
2116
|
-
|
|
932
|
+
include_base_tools : typing.Optional[bool]
|
|
933
|
+
If true, attaches the Letta core tools (e.g. archival_memory and core_memory related functions).
|
|
2117
934
|
|
|
2118
|
-
|
|
2119
|
-
|
|
935
|
+
include_multi_agent_tools : typing.Optional[bool]
|
|
936
|
+
If true, attaches the Letta multi-agent tools (e.g. sending a message to another agent).
|
|
2120
937
|
|
|
2121
938
|
description : typing.Optional[str]
|
|
2122
|
-
|
|
939
|
+
The description of the agent.
|
|
2123
940
|
|
|
2124
941
|
metadata : typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]]
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
request_options : typing.Optional[RequestOptions]
|
|
2128
|
-
Request-specific configuration.
|
|
2129
|
-
|
|
2130
|
-
Returns
|
|
2131
|
-
-------
|
|
2132
|
-
Block
|
|
2133
|
-
Successful Response
|
|
2134
|
-
|
|
2135
|
-
Examples
|
|
2136
|
-
--------
|
|
2137
|
-
import asyncio
|
|
2138
|
-
|
|
2139
|
-
from letta_client import AsyncLetta
|
|
2140
|
-
|
|
2141
|
-
client = AsyncLetta(
|
|
2142
|
-
token="YOUR_TOKEN",
|
|
2143
|
-
)
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
async def main() -> None:
|
|
2147
|
-
await client.agents.modify_core_memory_block(
|
|
2148
|
-
agent_id="agent_id",
|
|
2149
|
-
block_label="block_label",
|
|
2150
|
-
)
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
asyncio.run(main())
|
|
2154
|
-
"""
|
|
2155
|
-
_response = await self._client_wrapper.httpx_client.request(
|
|
2156
|
-
f"v1/agents/{jsonable_encoder(agent_id)}/core-memory/blocks/{jsonable_encoder(block_label)}",
|
|
2157
|
-
method="PATCH",
|
|
2158
|
-
json={
|
|
2159
|
-
"value": value,
|
|
2160
|
-
"limit": limit,
|
|
2161
|
-
"name": name,
|
|
2162
|
-
"is_template": is_template,
|
|
2163
|
-
"label": label,
|
|
2164
|
-
"description": description,
|
|
2165
|
-
"metadata": metadata,
|
|
2166
|
-
},
|
|
2167
|
-
request_options=request_options,
|
|
2168
|
-
omit=OMIT,
|
|
2169
|
-
)
|
|
2170
|
-
try:
|
|
2171
|
-
if 200 <= _response.status_code < 300:
|
|
2172
|
-
return typing.cast(
|
|
2173
|
-
Block,
|
|
2174
|
-
construct_type(
|
|
2175
|
-
type_=Block, # type: ignore
|
|
2176
|
-
object_=_response.json(),
|
|
2177
|
-
),
|
|
2178
|
-
)
|
|
2179
|
-
if _response.status_code == 422:
|
|
2180
|
-
raise UnprocessableEntityError(
|
|
2181
|
-
typing.cast(
|
|
2182
|
-
HttpValidationError,
|
|
2183
|
-
construct_type(
|
|
2184
|
-
type_=HttpValidationError, # type: ignore
|
|
2185
|
-
object_=_response.json(),
|
|
2186
|
-
),
|
|
2187
|
-
)
|
|
2188
|
-
)
|
|
2189
|
-
_response_json = _response.json()
|
|
2190
|
-
except JSONDecodeError:
|
|
2191
|
-
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
2192
|
-
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
2193
|
-
|
|
2194
|
-
async def list_core_memory_blocks(
|
|
2195
|
-
self, agent_id: str, *, request_options: typing.Optional[RequestOptions] = None
|
|
2196
|
-
) -> typing.List[Block]:
|
|
2197
|
-
"""
|
|
2198
|
-
Retrieve the memory blocks of a specific agent.
|
|
2199
|
-
|
|
2200
|
-
Parameters
|
|
2201
|
-
----------
|
|
2202
|
-
agent_id : str
|
|
2203
|
-
|
|
2204
|
-
request_options : typing.Optional[RequestOptions]
|
|
2205
|
-
Request-specific configuration.
|
|
2206
|
-
|
|
2207
|
-
Returns
|
|
2208
|
-
-------
|
|
2209
|
-
typing.List[Block]
|
|
2210
|
-
Successful Response
|
|
2211
|
-
|
|
2212
|
-
Examples
|
|
2213
|
-
--------
|
|
2214
|
-
import asyncio
|
|
942
|
+
The metadata of the agent.
|
|
2215
943
|
|
|
2216
|
-
|
|
944
|
+
model : typing.Optional[str]
|
|
945
|
+
The LLM configuration handle used by the agent, specified in the format provider/model-name, as an alternative to specifying llm_config.
|
|
2217
946
|
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
)
|
|
947
|
+
embedding : typing.Optional[str]
|
|
948
|
+
The embedding configuration handle used by the agent, specified in the format provider/model-name.
|
|
2221
949
|
|
|
950
|
+
context_window_limit : typing.Optional[int]
|
|
951
|
+
The context window limit used by the agent.
|
|
2222
952
|
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
agent_id="agent_id",
|
|
2226
|
-
)
|
|
953
|
+
embedding_chunk_size : typing.Optional[int]
|
|
954
|
+
The embedding chunk size used by the agent.
|
|
2227
955
|
|
|
956
|
+
from_template : typing.Optional[str]
|
|
957
|
+
The template id used to configure the agent
|
|
2228
958
|
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
_response = await self._client_wrapper.httpx_client.request(
|
|
2232
|
-
f"v1/agents/{jsonable_encoder(agent_id)}/core-memory/blocks",
|
|
2233
|
-
method="GET",
|
|
2234
|
-
request_options=request_options,
|
|
2235
|
-
)
|
|
2236
|
-
try:
|
|
2237
|
-
if 200 <= _response.status_code < 300:
|
|
2238
|
-
return typing.cast(
|
|
2239
|
-
typing.List[Block],
|
|
2240
|
-
construct_type(
|
|
2241
|
-
type_=typing.List[Block], # type: ignore
|
|
2242
|
-
object_=_response.json(),
|
|
2243
|
-
),
|
|
2244
|
-
)
|
|
2245
|
-
if _response.status_code == 422:
|
|
2246
|
-
raise UnprocessableEntityError(
|
|
2247
|
-
typing.cast(
|
|
2248
|
-
HttpValidationError,
|
|
2249
|
-
construct_type(
|
|
2250
|
-
type_=HttpValidationError, # type: ignore
|
|
2251
|
-
object_=_response.json(),
|
|
2252
|
-
),
|
|
2253
|
-
)
|
|
2254
|
-
)
|
|
2255
|
-
_response_json = _response.json()
|
|
2256
|
-
except JSONDecodeError:
|
|
2257
|
-
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
2258
|
-
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
959
|
+
template : typing.Optional[bool]
|
|
960
|
+
Whether the agent is a template
|
|
2259
961
|
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
) -> AgentState:
|
|
2263
|
-
"""
|
|
2264
|
-
Attach a block to an agent.
|
|
962
|
+
project : typing.Optional[str]
|
|
963
|
+
The project slug that the agent will be associated with.
|
|
2265
964
|
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
agent_id : str
|
|
965
|
+
tool_exec_environment_variables : typing.Optional[typing.Dict[str, typing.Optional[str]]]
|
|
966
|
+
The environment variables for tool execution specific to this agent.
|
|
2269
967
|
|
|
2270
|
-
|
|
968
|
+
memory_variables : typing.Optional[typing.Dict[str, typing.Optional[str]]]
|
|
969
|
+
The variables that should be set for the agent.
|
|
2271
970
|
|
|
2272
971
|
request_options : typing.Optional[RequestOptions]
|
|
2273
972
|
Request-specific configuration.
|
|
@@ -2289,18 +988,57 @@ class AsyncAgentsClient:
|
|
|
2289
988
|
|
|
2290
989
|
|
|
2291
990
|
async def main() -> None:
|
|
2292
|
-
await client.agents.
|
|
2293
|
-
agent_id="agent_id",
|
|
2294
|
-
block_id="block_id",
|
|
2295
|
-
)
|
|
991
|
+
await client.agents.create()
|
|
2296
992
|
|
|
2297
993
|
|
|
2298
994
|
asyncio.run(main())
|
|
2299
995
|
"""
|
|
2300
996
|
_response = await self._client_wrapper.httpx_client.request(
|
|
2301
|
-
|
|
2302
|
-
method="
|
|
997
|
+
"v1/agents/",
|
|
998
|
+
method="POST",
|
|
999
|
+
json={
|
|
1000
|
+
"name": name,
|
|
1001
|
+
"memory_blocks": convert_and_respect_annotation_metadata(
|
|
1002
|
+
object_=memory_blocks, annotation=typing.Sequence[CreateBlock], direction="write"
|
|
1003
|
+
),
|
|
1004
|
+
"tools": tools,
|
|
1005
|
+
"tool_ids": tool_ids,
|
|
1006
|
+
"source_ids": source_ids,
|
|
1007
|
+
"block_ids": block_ids,
|
|
1008
|
+
"tool_rules": convert_and_respect_annotation_metadata(
|
|
1009
|
+
object_=tool_rules, annotation=typing.Sequence[CreateAgentRequestToolRulesItem], direction="write"
|
|
1010
|
+
),
|
|
1011
|
+
"tags": tags,
|
|
1012
|
+
"system": system,
|
|
1013
|
+
"agent_type": agent_type,
|
|
1014
|
+
"llm_config": convert_and_respect_annotation_metadata(
|
|
1015
|
+
object_=llm_config, annotation=LlmConfig, direction="write"
|
|
1016
|
+
),
|
|
1017
|
+
"embedding_config": convert_and_respect_annotation_metadata(
|
|
1018
|
+
object_=embedding_config, annotation=EmbeddingConfig, direction="write"
|
|
1019
|
+
),
|
|
1020
|
+
"initial_message_sequence": convert_and_respect_annotation_metadata(
|
|
1021
|
+
object_=initial_message_sequence, annotation=typing.Sequence[MessageCreate], direction="write"
|
|
1022
|
+
),
|
|
1023
|
+
"include_base_tools": include_base_tools,
|
|
1024
|
+
"include_multi_agent_tools": include_multi_agent_tools,
|
|
1025
|
+
"description": description,
|
|
1026
|
+
"metadata": metadata,
|
|
1027
|
+
"model": model,
|
|
1028
|
+
"embedding": embedding,
|
|
1029
|
+
"context_window_limit": context_window_limit,
|
|
1030
|
+
"embedding_chunk_size": embedding_chunk_size,
|
|
1031
|
+
"from_template": from_template,
|
|
1032
|
+
"template": template,
|
|
1033
|
+
"project": project,
|
|
1034
|
+
"tool_exec_environment_variables": tool_exec_environment_variables,
|
|
1035
|
+
"memory_variables": memory_variables,
|
|
1036
|
+
},
|
|
1037
|
+
headers={
|
|
1038
|
+
"content-type": "application/json",
|
|
1039
|
+
},
|
|
2303
1040
|
request_options=request_options,
|
|
1041
|
+
omit=OMIT,
|
|
2304
1042
|
)
|
|
2305
1043
|
try:
|
|
2306
1044
|
if 200 <= _response.status_code < 300:
|
|
@@ -2326,18 +1064,14 @@ class AsyncAgentsClient:
|
|
|
2326
1064
|
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
2327
1065
|
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
2328
1066
|
|
|
2329
|
-
async def
|
|
2330
|
-
self, agent_id: str, block_id: str, *, request_options: typing.Optional[RequestOptions] = None
|
|
2331
|
-
) -> AgentState:
|
|
1067
|
+
async def retrieve(self, agent_id: str, *, request_options: typing.Optional[RequestOptions] = None) -> AgentState:
|
|
2332
1068
|
"""
|
|
2333
|
-
|
|
1069
|
+
Get the state of the agent.
|
|
2334
1070
|
|
|
2335
1071
|
Parameters
|
|
2336
1072
|
----------
|
|
2337
1073
|
agent_id : str
|
|
2338
1074
|
|
|
2339
|
-
block_id : str
|
|
2340
|
-
|
|
2341
1075
|
request_options : typing.Optional[RequestOptions]
|
|
2342
1076
|
Request-specific configuration.
|
|
2343
1077
|
|
|
@@ -2358,17 +1092,16 @@ class AsyncAgentsClient:
|
|
|
2358
1092
|
|
|
2359
1093
|
|
|
2360
1094
|
async def main() -> None:
|
|
2361
|
-
await client.agents.
|
|
1095
|
+
await client.agents.retrieve(
|
|
2362
1096
|
agent_id="agent_id",
|
|
2363
|
-
block_id="block_id",
|
|
2364
1097
|
)
|
|
2365
1098
|
|
|
2366
1099
|
|
|
2367
1100
|
asyncio.run(main())
|
|
2368
1101
|
"""
|
|
2369
1102
|
_response = await self._client_wrapper.httpx_client.request(
|
|
2370
|
-
f"v1/agents/{jsonable_encoder(agent_id)}
|
|
2371
|
-
method="
|
|
1103
|
+
f"v1/agents/{jsonable_encoder(agent_id)}",
|
|
1104
|
+
method="GET",
|
|
2372
1105
|
request_options=request_options,
|
|
2373
1106
|
)
|
|
2374
1107
|
try:
|
|
@@ -2395,37 +1128,22 @@ class AsyncAgentsClient:
|
|
|
2395
1128
|
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
2396
1129
|
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
2397
1130
|
|
|
2398
|
-
async def
|
|
2399
|
-
self,
|
|
2400
|
-
|
|
2401
|
-
*,
|
|
2402
|
-
after: typing.Optional[int] = None,
|
|
2403
|
-
before: typing.Optional[int] = None,
|
|
2404
|
-
limit: typing.Optional[int] = None,
|
|
2405
|
-
request_options: typing.Optional[RequestOptions] = None,
|
|
2406
|
-
) -> typing.List[Passage]:
|
|
1131
|
+
async def delete(
|
|
1132
|
+
self, agent_id: str, *, request_options: typing.Optional[RequestOptions] = None
|
|
1133
|
+
) -> typing.Optional[typing.Any]:
|
|
2407
1134
|
"""
|
|
2408
|
-
|
|
1135
|
+
Delete an agent.
|
|
2409
1136
|
|
|
2410
1137
|
Parameters
|
|
2411
1138
|
----------
|
|
2412
1139
|
agent_id : str
|
|
2413
1140
|
|
|
2414
|
-
after : typing.Optional[int]
|
|
2415
|
-
Unique ID of the memory to start the query range at.
|
|
2416
|
-
|
|
2417
|
-
before : typing.Optional[int]
|
|
2418
|
-
Unique ID of the memory to end the query range at.
|
|
2419
|
-
|
|
2420
|
-
limit : typing.Optional[int]
|
|
2421
|
-
How many results to include in the response.
|
|
2422
|
-
|
|
2423
1141
|
request_options : typing.Optional[RequestOptions]
|
|
2424
1142
|
Request-specific configuration.
|
|
2425
1143
|
|
|
2426
1144
|
Returns
|
|
2427
1145
|
-------
|
|
2428
|
-
typing.
|
|
1146
|
+
typing.Optional[typing.Any]
|
|
2429
1147
|
Successful Response
|
|
2430
1148
|
|
|
2431
1149
|
Examples
|
|
@@ -2440,7 +1158,7 @@ class AsyncAgentsClient:
|
|
|
2440
1158
|
|
|
2441
1159
|
|
|
2442
1160
|
async def main() -> None:
|
|
2443
|
-
await client.agents.
|
|
1161
|
+
await client.agents.delete(
|
|
2444
1162
|
agent_id="agent_id",
|
|
2445
1163
|
)
|
|
2446
1164
|
|
|
@@ -2448,21 +1166,16 @@ class AsyncAgentsClient:
|
|
|
2448
1166
|
asyncio.run(main())
|
|
2449
1167
|
"""
|
|
2450
1168
|
_response = await self._client_wrapper.httpx_client.request(
|
|
2451
|
-
f"v1/agents/{jsonable_encoder(agent_id)}
|
|
2452
|
-
method="
|
|
2453
|
-
params={
|
|
2454
|
-
"after": after,
|
|
2455
|
-
"before": before,
|
|
2456
|
-
"limit": limit,
|
|
2457
|
-
},
|
|
1169
|
+
f"v1/agents/{jsonable_encoder(agent_id)}",
|
|
1170
|
+
method="DELETE",
|
|
2458
1171
|
request_options=request_options,
|
|
2459
1172
|
)
|
|
2460
1173
|
try:
|
|
2461
1174
|
if 200 <= _response.status_code < 300:
|
|
2462
1175
|
return typing.cast(
|
|
2463
|
-
typing.
|
|
1176
|
+
typing.Optional[typing.Any],
|
|
2464
1177
|
construct_type(
|
|
2465
|
-
type_=typing.
|
|
1178
|
+
type_=typing.Optional[typing.Any], # type: ignore
|
|
2466
1179
|
object_=_response.json(),
|
|
2467
1180
|
),
|
|
2468
1181
|
)
|
|
@@ -2481,101 +1194,77 @@ class AsyncAgentsClient:
|
|
|
2481
1194
|
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
2482
1195
|
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
2483
1196
|
|
|
2484
|
-
async def
|
|
2485
|
-
self,
|
|
2486
|
-
|
|
1197
|
+
async def modify(
|
|
1198
|
+
self,
|
|
1199
|
+
agent_id: str,
|
|
1200
|
+
*,
|
|
1201
|
+
name: typing.Optional[str] = OMIT,
|
|
1202
|
+
tool_ids: typing.Optional[typing.Sequence[str]] = OMIT,
|
|
1203
|
+
source_ids: typing.Optional[typing.Sequence[str]] = OMIT,
|
|
1204
|
+
block_ids: typing.Optional[typing.Sequence[str]] = OMIT,
|
|
1205
|
+
tags: typing.Optional[typing.Sequence[str]] = OMIT,
|
|
1206
|
+
system: typing.Optional[str] = OMIT,
|
|
1207
|
+
tool_rules: typing.Optional[typing.Sequence[UpdateAgentToolRulesItem]] = OMIT,
|
|
1208
|
+
llm_config: typing.Optional[LlmConfig] = OMIT,
|
|
1209
|
+
embedding_config: typing.Optional[EmbeddingConfig] = OMIT,
|
|
1210
|
+
message_ids: typing.Optional[typing.Sequence[str]] = OMIT,
|
|
1211
|
+
description: typing.Optional[str] = OMIT,
|
|
1212
|
+
metadata: typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]] = OMIT,
|
|
1213
|
+
tool_exec_environment_variables: typing.Optional[typing.Dict[str, typing.Optional[str]]] = OMIT,
|
|
1214
|
+
request_options: typing.Optional[RequestOptions] = None,
|
|
1215
|
+
) -> AgentState:
|
|
2487
1216
|
"""
|
|
2488
|
-
|
|
1217
|
+
Update an existing agent
|
|
2489
1218
|
|
|
2490
1219
|
Parameters
|
|
2491
1220
|
----------
|
|
2492
1221
|
agent_id : str
|
|
2493
1222
|
|
|
2494
|
-
|
|
2495
|
-
|
|
1223
|
+
name : typing.Optional[str]
|
|
1224
|
+
The name of the agent.
|
|
2496
1225
|
|
|
2497
|
-
|
|
2498
|
-
|
|
1226
|
+
tool_ids : typing.Optional[typing.Sequence[str]]
|
|
1227
|
+
The ids of the tools used by the agent.
|
|
2499
1228
|
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
typing.List[Passage]
|
|
2503
|
-
Successful Response
|
|
1229
|
+
source_ids : typing.Optional[typing.Sequence[str]]
|
|
1230
|
+
The ids of the sources used by the agent.
|
|
2504
1231
|
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
import asyncio
|
|
1232
|
+
block_ids : typing.Optional[typing.Sequence[str]]
|
|
1233
|
+
The ids of the blocks used by the agent.
|
|
2508
1234
|
|
|
2509
|
-
|
|
1235
|
+
tags : typing.Optional[typing.Sequence[str]]
|
|
1236
|
+
The tags associated with the agent.
|
|
2510
1237
|
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
)
|
|
1238
|
+
system : typing.Optional[str]
|
|
1239
|
+
The system prompt used by the agent.
|
|
2514
1240
|
|
|
1241
|
+
tool_rules : typing.Optional[typing.Sequence[UpdateAgentToolRulesItem]]
|
|
1242
|
+
The tool rules governing the agent.
|
|
2515
1243
|
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
agent_id="agent_id",
|
|
2519
|
-
text="text",
|
|
2520
|
-
)
|
|
1244
|
+
llm_config : typing.Optional[LlmConfig]
|
|
1245
|
+
The LLM configuration used by the agent.
|
|
2521
1246
|
|
|
1247
|
+
embedding_config : typing.Optional[EmbeddingConfig]
|
|
1248
|
+
The embedding configuration used by the agent.
|
|
2522
1249
|
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
_response = await self._client_wrapper.httpx_client.request(
|
|
2526
|
-
f"v1/agents/{jsonable_encoder(agent_id)}/archival-memory",
|
|
2527
|
-
method="POST",
|
|
2528
|
-
json={
|
|
2529
|
-
"text": text,
|
|
2530
|
-
},
|
|
2531
|
-
headers={
|
|
2532
|
-
"content-type": "application/json",
|
|
2533
|
-
},
|
|
2534
|
-
request_options=request_options,
|
|
2535
|
-
omit=OMIT,
|
|
2536
|
-
)
|
|
2537
|
-
try:
|
|
2538
|
-
if 200 <= _response.status_code < 300:
|
|
2539
|
-
return typing.cast(
|
|
2540
|
-
typing.List[Passage],
|
|
2541
|
-
construct_type(
|
|
2542
|
-
type_=typing.List[Passage], # type: ignore
|
|
2543
|
-
object_=_response.json(),
|
|
2544
|
-
),
|
|
2545
|
-
)
|
|
2546
|
-
if _response.status_code == 422:
|
|
2547
|
-
raise UnprocessableEntityError(
|
|
2548
|
-
typing.cast(
|
|
2549
|
-
HttpValidationError,
|
|
2550
|
-
construct_type(
|
|
2551
|
-
type_=HttpValidationError, # type: ignore
|
|
2552
|
-
object_=_response.json(),
|
|
2553
|
-
),
|
|
2554
|
-
)
|
|
2555
|
-
)
|
|
2556
|
-
_response_json = _response.json()
|
|
2557
|
-
except JSONDecodeError:
|
|
2558
|
-
raise ApiError(status_code=_response.status_code, body=_response.text)
|
|
2559
|
-
raise ApiError(status_code=_response.status_code, body=_response_json)
|
|
1250
|
+
message_ids : typing.Optional[typing.Sequence[str]]
|
|
1251
|
+
The ids of the messages in the agent's in-context memory.
|
|
2560
1252
|
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
) -> typing.Optional[typing.Any]:
|
|
2564
|
-
"""
|
|
2565
|
-
Delete a memory from an agent's archival memory store.
|
|
1253
|
+
description : typing.Optional[str]
|
|
1254
|
+
The description of the agent.
|
|
2566
1255
|
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
agent_id : str
|
|
1256
|
+
metadata : typing.Optional[typing.Dict[str, typing.Optional[typing.Any]]]
|
|
1257
|
+
The metadata of the agent.
|
|
2570
1258
|
|
|
2571
|
-
|
|
1259
|
+
tool_exec_environment_variables : typing.Optional[typing.Dict[str, typing.Optional[str]]]
|
|
1260
|
+
The environment variables for tool execution specific to this agent.
|
|
2572
1261
|
|
|
2573
1262
|
request_options : typing.Optional[RequestOptions]
|
|
2574
1263
|
Request-specific configuration.
|
|
2575
1264
|
|
|
2576
1265
|
Returns
|
|
2577
1266
|
-------
|
|
2578
|
-
|
|
1267
|
+
AgentState
|
|
2579
1268
|
Successful Response
|
|
2580
1269
|
|
|
2581
1270
|
Examples
|
|
@@ -2590,25 +1279,49 @@ class AsyncAgentsClient:
|
|
|
2590
1279
|
|
|
2591
1280
|
|
|
2592
1281
|
async def main() -> None:
|
|
2593
|
-
await client.agents.
|
|
1282
|
+
await client.agents.modify(
|
|
2594
1283
|
agent_id="agent_id",
|
|
2595
|
-
memory_id="memory_id",
|
|
2596
1284
|
)
|
|
2597
1285
|
|
|
2598
1286
|
|
|
2599
1287
|
asyncio.run(main())
|
|
2600
1288
|
"""
|
|
2601
1289
|
_response = await self._client_wrapper.httpx_client.request(
|
|
2602
|
-
f"v1/agents/{jsonable_encoder(agent_id)}
|
|
2603
|
-
method="
|
|
1290
|
+
f"v1/agents/{jsonable_encoder(agent_id)}",
|
|
1291
|
+
method="PATCH",
|
|
1292
|
+
json={
|
|
1293
|
+
"name": name,
|
|
1294
|
+
"tool_ids": tool_ids,
|
|
1295
|
+
"source_ids": source_ids,
|
|
1296
|
+
"block_ids": block_ids,
|
|
1297
|
+
"tags": tags,
|
|
1298
|
+
"system": system,
|
|
1299
|
+
"tool_rules": convert_and_respect_annotation_metadata(
|
|
1300
|
+
object_=tool_rules, annotation=typing.Sequence[UpdateAgentToolRulesItem], direction="write"
|
|
1301
|
+
),
|
|
1302
|
+
"llm_config": convert_and_respect_annotation_metadata(
|
|
1303
|
+
object_=llm_config, annotation=LlmConfig, direction="write"
|
|
1304
|
+
),
|
|
1305
|
+
"embedding_config": convert_and_respect_annotation_metadata(
|
|
1306
|
+
object_=embedding_config, annotation=EmbeddingConfig, direction="write"
|
|
1307
|
+
),
|
|
1308
|
+
"message_ids": message_ids,
|
|
1309
|
+
"description": description,
|
|
1310
|
+
"metadata": metadata,
|
|
1311
|
+
"tool_exec_environment_variables": tool_exec_environment_variables,
|
|
1312
|
+
},
|
|
1313
|
+
headers={
|
|
1314
|
+
"content-type": "application/json",
|
|
1315
|
+
},
|
|
2604
1316
|
request_options=request_options,
|
|
1317
|
+
omit=OMIT,
|
|
2605
1318
|
)
|
|
2606
1319
|
try:
|
|
2607
1320
|
if 200 <= _response.status_code < 300:
|
|
2608
1321
|
return typing.cast(
|
|
2609
|
-
|
|
1322
|
+
AgentState,
|
|
2610
1323
|
construct_type(
|
|
2611
|
-
type_=
|
|
1324
|
+
type_=AgentState, # type: ignore
|
|
2612
1325
|
object_=_response.json(),
|
|
2613
1326
|
),
|
|
2614
1327
|
)
|