nora-lib-impl 1.8.0__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.
nora_lib/__init__.py ADDED
File without changes
File without changes
File without changes
@@ -0,0 +1,50 @@
1
+ from typing import Optional
2
+ from uuid import UUID
3
+
4
+ from nora_lib.impl.interactions.models import Surface
5
+ from pydantic import BaseModel
6
+
7
+ from nora_lib.serializers import UuidWithSerializer
8
+
9
+
10
+ class MessageAgentContext(BaseModel):
11
+ """
12
+ Identifiers for the triggering message
13
+ """
14
+
15
+ message_id: str
16
+ thread_id: str
17
+ channel_id: str
18
+ # Pydantic models don't actually need this, but some codebases pass model_dump() objects
19
+ # to other JSON serializers (e.g. FastAPI) which don't handle UUIDs and other python built-ins.
20
+ # So we use this special UUID wrapper for convenience.
21
+ actor_id: UuidWithSerializer
22
+ surface: Surface
23
+
24
+
25
+ class PubsubAgentContext(BaseModel):
26
+ """
27
+ The pubsub namespace in which the Handler is running
28
+ """
29
+
30
+ base_url: str
31
+ namespace: str
32
+
33
+
34
+ class ToolConfigAgentContext(BaseModel):
35
+ """
36
+ The name of the tool config being used by the handler (dev, prod, demo, etc.)
37
+ """
38
+
39
+ env: str
40
+
41
+
42
+ class AgentContext(BaseModel):
43
+ """
44
+ Information that needs to be passed from the Handler to tool agents
45
+ """
46
+
47
+ message: MessageAgentContext
48
+ pubsub: PubsubAgentContext
49
+ tool_config: ToolConfigAgentContext
50
+ step_id: Optional[str] = None
@@ -0,0 +1,33 @@
1
+ from typing import Optional
2
+
3
+ from nora_lib.impl.interactions.interactions_service import InteractionsService
4
+ from nora_lib.impl.interactions.models import ReturnedMessage
5
+
6
+
7
+ class ContextService:
8
+ """
9
+ Save and retrieve task agent context from interaction store
10
+ """
11
+
12
+ def __init__(
13
+ self,
14
+ agent_actor_id: str, # uuid representing this agent in interaction store
15
+ interactions_base_url: str,
16
+ interactions_bearer_token: Optional[str],
17
+ timeout: int = 30,
18
+ ):
19
+ # If no config is provided, load the configuration based on the environment
20
+ self.interactions_service = self._get_interactions_service(
21
+ interactions_base_url, interactions_bearer_token, timeout
22
+ )
23
+ self.agent_actor_id = agent_actor_id
24
+
25
+ def _get_interactions_service(self, url, token, timeout) -> InteractionsService:
26
+ return InteractionsService(url, timeout, token)
27
+
28
+ def get_message(self, message_id: str) -> str:
29
+ message: ReturnedMessage = self.interactions_service.get_message(message_id)
30
+ if message.annotated_text:
31
+ return message.annotated_text
32
+ else:
33
+ return message.text
@@ -0,0 +1,11 @@
1
+ from typing import Optional
2
+ from pydantic import BaseModel, Field
3
+
4
+
5
+ class WrappedTaskObject(BaseModel):
6
+ """Encloses request or response object with additional metadata"""
7
+
8
+ message_id: str = Field(
9
+ description="id of originating message; key for istore retrieval"
10
+ )
11
+ data: dict = Field(description="Tool-defined request or response")
File without changes