11from __future__ import annotations
2+ import enum
23from typing import List , Optional , Dict , Any , Union
34
45
5- class AiAgentParameter :
6- """
7- Represents a parameter for an AI agent configuration.
8- Parameters can be used to pass values to the agent's system prompt.
9- """
6+ class AiAgentParameterPolicy (enum .IntFlag ):
7+ # FORBID_MODEL_GENERATION blocks a parent agent from generating values for
8+ # this parameter when invoking a sub-agent that declares it.
9+ DEFAULT = 0
10+ FORBID_MODEL_GENERATION = 1
11+
12+
13+ class AiAgentParameterValueType (enum .Enum ):
14+ DEFAULT = "Default"
15+ STRING = "String"
16+ NUMBER = "Number"
17+ BOOLEAN = "Boolean"
18+ ARRAY_OF_STRING = "ArrayOfString"
19+ ARRAY_OF_NUMBER = "ArrayOfNumber"
20+ ARRAY_OF_BOOLEAN = "ArrayOfBoolean"
21+ NULL = "Null"
22+
23+ def __str__ (self ) -> str :
24+ return self .value
1025
26+
27+ class AiAgentParameter :
1128 def __init__ (
1229 self ,
1330 name : str = None ,
1431 description : str = None ,
1532 send_to_model : bool = None ,
33+ policy : AiAgentParameterPolicy = AiAgentParameterPolicy .DEFAULT ,
34+ type : AiAgentParameterValueType = AiAgentParameterValueType .DEFAULT ,
1635 ):
17- """
18- Initialize an agent parameter.
19-
20- Args:
21- name: The parameter name. Cannot be null or empty.
22- description: A human-readable description. May be null or empty.
23- send_to_model: When False, the parameter is hidden from the model
24- (it will not be included in prompts/echo messages).
25- When True, the parameter is exposed to the model.
26- If None (default), treated as exposed.
27- """
2836 self .name = name
2937 self .description : Optional [str ] = description
3038 self .send_to_model : Optional [bool ] = send_to_model
39+ self .policy : AiAgentParameterPolicy = policy
40+ self .type : AiAgentParameterValueType = type
3141
3242 def to_json (self ) -> Dict [str , Any ]:
3343 return {
3444 "Name" : self .name ,
3545 "Description" : self .description ,
3646 "SendToModel" : self .send_to_model ,
47+ "Policy" : int (self .policy ),
48+ "Type" : self .type .value ,
3749 }
3850
3951 @classmethod
4052 def from_json (cls , json_dict : Dict [str , Any ]) -> AiAgentParameter :
53+ # Server emits Policy as either int (1) or PascalCase ("ForbidModelGeneration").
54+ policy_raw = json_dict .get ("policy" ) if "policy" in json_dict else json_dict .get ("Policy" )
55+ if policy_raw is None or policy_raw == 0 or policy_raw == "" :
56+ policy = AiAgentParameterPolicy .DEFAULT
57+ elif isinstance (policy_raw , str ):
58+ snake = "" .join ("_" + c if i > 0 and c .isupper () else c for i , c in enumerate (policy_raw )).upper ()
59+ policy = AiAgentParameterPolicy [snake ]
60+ else :
61+ policy = AiAgentParameterPolicy (policy_raw )
62+
63+ type_raw = json_dict .get ("type" ) if "type" in json_dict else json_dict .get ("Type" )
64+ type_ = AiAgentParameterValueType (type_raw ) if type_raw else AiAgentParameterValueType .DEFAULT
65+
4166 return cls (
4267 name = json_dict .get ("name" ) or json_dict .get ("Name" ),
4368 description = json_dict .get ("description" ) or json_dict .get ("Description" ),
4469 send_to_model = json_dict .get ("sendToModel" ) if "sendToModel" in json_dict else json_dict .get ("SendToModel" ),
70+ policy = policy ,
71+ type = type_ ,
4572 )
4673
4774
4875class AiAgentToolQuery :
49- """
50- Represents a query tool that can be invoked by an AI agent.
51- The tool includes a name, description, query string, and parameter schema or sample object.
52- When invoked by the AI model, the query is expected to be executed by the server (database),
53- and its results provided back to the model.
54- """
55-
76+ # Database-side RQL the model can call. Results are sent back to the model.
5677 def __init__ (
5778 self ,
5879 name : str = None ,
@@ -98,12 +119,8 @@ def from_json(cls, json_dict: Dict[str, Any]) -> AiAgentToolQuery:
98119
99120
100121class AiAgentToolAction :
101- """
102- Represents a tool action that can be invoked by an AI agent.
103- Includes metadata such as name, description, and optional parameters schema or sample.
104- Tool actions represent external functions whose results are provided by the user
105- """
106-
122+ # External function the model can call. Its result is supplied by the user
123+ # (vs AiAgentToolQuery whose result comes from the database).
107124 def __init__ (
108125 self ,
109126 name : str = None ,
@@ -137,11 +154,6 @@ def from_json(cls, json_dict: Dict[str, Any]) -> AiAgentToolAction:
137154
138155
139156class AiAgentPersistenceConfiguration :
140- """
141- Configuration for persisting chat history in RavenDB.
142- Defines where chat sessions should be stored and optionally how long they should be retained (expiration).
143- """
144-
145157 def __init__ (self , conversation_id_prefix : str = None , expires : int = None ):
146158 self .conversation_id_prefix = conversation_id_prefix
147159 self .conversation_expiration_in_sec : Optional [int ] = expires
@@ -163,10 +175,6 @@ def from_json(cls, json_dict: Dict[str, Any]) -> AiAgentPersistenceConfiguration
163175
164176
165177class AiAgentSummarizationByTokens :
166- """
167- Configuration settings for AI agent conversation summarization.
168- """
169-
170178 DEFAULT_MAX_TOKENS_BEFORE_SUMMARIZATION = 32 * 1024
171179
172180 def __init__ (
@@ -208,10 +216,6 @@ def from_json(cls, json_dict: Dict[str, Any]) -> AiAgentSummarizationByTokens:
208216
209217
210218class AiAgentTruncateChat :
211- """
212- Configuration for truncating the AI chat history based on message count.
213- """
214-
215219 DEFAULT_MESSAGES_LENGTH_BEFORE_TRUNCATE = 500
216220
217221 def __init__ (self , messages_length_before_truncate : int = None , messages_length_after_truncate : int = None ):
@@ -241,10 +245,6 @@ def from_json(cls, json_dict: Dict[str, Any]) -> AiAgentTruncateChat:
241245
242246
243247class AiAgentHistoryConfiguration :
244- """
245- Defines the configuration for retention and expiration of AI agent chat history documents.
246- """
247-
248248 def __init__ (self , history_expiration_in_sec : int = None ):
249249 self .history_expiration_in_sec : Optional [int ] = history_expiration_in_sec
250250
@@ -261,10 +261,6 @@ def from_json(cls, json_dict: Dict[str, Any]) -> AiAgentHistoryConfiguration:
261261
262262
263263class AiAgentChatTrimmingConfiguration :
264- """
265- Defines configuration options for reducing the size of the AI agent's chat history.
266- """
267-
268264 def __init__ (
269265 self ,
270266 tokens_config : AiAgentSummarizationByTokens = None ,
@@ -295,11 +291,6 @@ def from_json(cls, json_dict: Dict[str, Any]) -> AiAgentChatTrimmingConfiguratio
295291
296292
297293class AiAgentConfiguration :
298- """
299- Defines the configuration for an AI agent in RavenDB, including the system prompt,
300- tools (queries/actions), output schema, persistence settings, and connection string.
301- """
302-
303294 def __init__ (
304295 self ,
305296 name : str = None ,
@@ -363,7 +354,6 @@ def to_json(self) -> Dict[str, Any]:
363354 @classmethod
364355 def from_json (cls , json_dict : Dict [str , Any ]) -> AiAgentConfiguration :
365356 instance = cls ()
366- # Handle both camelCase and PascalCase for compatibility
367357 instance .identifier = json_dict .get ("identifier" ) or json_dict .get ("Identifier" )
368358 instance .name = json_dict .get ("name" ) or json_dict .get ("Name" )
369359 instance .connection_string_name = json_dict .get ("connectionStringName" ) or json_dict .get ("ConnectionStringName" )
0 commit comments