forked from CopilotKit/CopilotKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathagent.py
More file actions
59 lines (52 loc) · 1.43 KB
/
Copy pathagent.py
File metadata and controls
59 lines (52 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
"""Agents"""
from typing import Optional, List, TypedDict
from abc import ABC, abstractmethod
from .types import Message
from .action import ActionDict
from .types import MetaEvent
class AgentDict(TypedDict):
"""Agent dictionary"""
name: str
description: Optional[str]
class Agent(ABC):
"""Agent class for CopilotKit"""
def __init__(
self,
*,
name: str,
description: Optional[str] = None,
):
self.name = name
self.description = description
@abstractmethod
def execute( # pylint: disable=too-many-arguments
self,
*,
state: dict,
configurable: Optional[dict] = None,
messages: List[Message],
thread_id: Optional[str] = None,
node_name: Optional[str] = None,
actions: Optional[List[ActionDict]] = None,
meta_events: Optional[List[MetaEvent]] = None,
):
"""Execute the agent"""
@abstractmethod
async def get_state(
self,
*,
thread_id: str,
):
"""Default get_state implementation"""
return {
"threadId": thread_id or "",
"threadExists": False,
"state": {},
"messages": []
}
def dict_repr(self) -> AgentDict:
"""Dict representation of the action"""
return {
'name': self.name,
'description': self.description or ''
}