hackagent 0.3.1__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.
Files changed (183) hide show
  1. hackagent/__init__.py +12 -0
  2. hackagent/agent.py +214 -0
  3. hackagent/api/__init__.py +1 -0
  4. hackagent/api/agent/__init__.py +1 -0
  5. hackagent/api/agent/agent_create.py +347 -0
  6. hackagent/api/agent/agent_destroy.py +140 -0
  7. hackagent/api/agent/agent_list.py +242 -0
  8. hackagent/api/agent/agent_partial_update.py +361 -0
  9. hackagent/api/agent/agent_retrieve.py +235 -0
  10. hackagent/api/agent/agent_update.py +361 -0
  11. hackagent/api/apilogs/__init__.py +1 -0
  12. hackagent/api/apilogs/apilogs_list.py +170 -0
  13. hackagent/api/apilogs/apilogs_retrieve.py +162 -0
  14. hackagent/api/attack/__init__.py +1 -0
  15. hackagent/api/attack/attack_create.py +275 -0
  16. hackagent/api/attack/attack_destroy.py +146 -0
  17. hackagent/api/attack/attack_list.py +254 -0
  18. hackagent/api/attack/attack_partial_update.py +289 -0
  19. hackagent/api/attack/attack_retrieve.py +247 -0
  20. hackagent/api/attack/attack_update.py +289 -0
  21. hackagent/api/checkout/__init__.py +1 -0
  22. hackagent/api/checkout/checkout_create.py +225 -0
  23. hackagent/api/generate/__init__.py +1 -0
  24. hackagent/api/generate/generate_create.py +253 -0
  25. hackagent/api/judge/__init__.py +1 -0
  26. hackagent/api/judge/judge_create.py +253 -0
  27. hackagent/api/key/__init__.py +1 -0
  28. hackagent/api/key/key_create.py +179 -0
  29. hackagent/api/key/key_destroy.py +103 -0
  30. hackagent/api/key/key_list.py +170 -0
  31. hackagent/api/key/key_retrieve.py +162 -0
  32. hackagent/api/organization/__init__.py +1 -0
  33. hackagent/api/organization/organization_create.py +208 -0
  34. hackagent/api/organization/organization_destroy.py +104 -0
  35. hackagent/api/organization/organization_list.py +170 -0
  36. hackagent/api/organization/organization_me_retrieve.py +126 -0
  37. hackagent/api/organization/organization_partial_update.py +222 -0
  38. hackagent/api/organization/organization_retrieve.py +163 -0
  39. hackagent/api/organization/organization_update.py +222 -0
  40. hackagent/api/prompt/__init__.py +1 -0
  41. hackagent/api/prompt/prompt_create.py +171 -0
  42. hackagent/api/prompt/prompt_destroy.py +104 -0
  43. hackagent/api/prompt/prompt_list.py +185 -0
  44. hackagent/api/prompt/prompt_partial_update.py +185 -0
  45. hackagent/api/prompt/prompt_retrieve.py +163 -0
  46. hackagent/api/prompt/prompt_update.py +185 -0
  47. hackagent/api/result/__init__.py +1 -0
  48. hackagent/api/result/result_create.py +175 -0
  49. hackagent/api/result/result_destroy.py +106 -0
  50. hackagent/api/result/result_list.py +249 -0
  51. hackagent/api/result/result_partial_update.py +193 -0
  52. hackagent/api/result/result_retrieve.py +167 -0
  53. hackagent/api/result/result_trace_create.py +177 -0
  54. hackagent/api/result/result_update.py +189 -0
  55. hackagent/api/run/__init__.py +1 -0
  56. hackagent/api/run/run_create.py +187 -0
  57. hackagent/api/run/run_destroy.py +112 -0
  58. hackagent/api/run/run_list.py +291 -0
  59. hackagent/api/run/run_partial_update.py +201 -0
  60. hackagent/api/run/run_result_create.py +177 -0
  61. hackagent/api/run/run_retrieve.py +179 -0
  62. hackagent/api/run/run_run_tests_create.py +187 -0
  63. hackagent/api/run/run_update.py +201 -0
  64. hackagent/api/user/__init__.py +1 -0
  65. hackagent/api/user/user_create.py +212 -0
  66. hackagent/api/user/user_destroy.py +106 -0
  67. hackagent/api/user/user_list.py +174 -0
  68. hackagent/api/user/user_me_retrieve.py +126 -0
  69. hackagent/api/user/user_me_update.py +196 -0
  70. hackagent/api/user/user_partial_update.py +226 -0
  71. hackagent/api/user/user_retrieve.py +167 -0
  72. hackagent/api/user/user_update.py +226 -0
  73. hackagent/attacks/AdvPrefix/__init__.py +41 -0
  74. hackagent/attacks/AdvPrefix/completions.py +416 -0
  75. hackagent/attacks/AdvPrefix/config.py +259 -0
  76. hackagent/attacks/AdvPrefix/evaluation.py +745 -0
  77. hackagent/attacks/AdvPrefix/evaluators.py +564 -0
  78. hackagent/attacks/AdvPrefix/generate.py +711 -0
  79. hackagent/attacks/AdvPrefix/utils.py +307 -0
  80. hackagent/attacks/__init__.py +35 -0
  81. hackagent/attacks/advprefix.py +507 -0
  82. hackagent/attacks/base.py +106 -0
  83. hackagent/attacks/strategies.py +906 -0
  84. hackagent/cli/__init__.py +19 -0
  85. hackagent/cli/commands/__init__.py +20 -0
  86. hackagent/cli/commands/agent.py +100 -0
  87. hackagent/cli/commands/attack.py +417 -0
  88. hackagent/cli/commands/config.py +301 -0
  89. hackagent/cli/commands/results.py +327 -0
  90. hackagent/cli/config.py +249 -0
  91. hackagent/cli/main.py +515 -0
  92. hackagent/cli/tui/__init__.py +31 -0
  93. hackagent/cli/tui/actions_logger.py +200 -0
  94. hackagent/cli/tui/app.py +288 -0
  95. hackagent/cli/tui/base.py +137 -0
  96. hackagent/cli/tui/logger.py +318 -0
  97. hackagent/cli/tui/views/__init__.py +33 -0
  98. hackagent/cli/tui/views/agents.py +488 -0
  99. hackagent/cli/tui/views/attacks.py +624 -0
  100. hackagent/cli/tui/views/config.py +244 -0
  101. hackagent/cli/tui/views/dashboard.py +307 -0
  102. hackagent/cli/tui/views/results.py +1210 -0
  103. hackagent/cli/tui/widgets/__init__.py +24 -0
  104. hackagent/cli/tui/widgets/actions.py +346 -0
  105. hackagent/cli/tui/widgets/logs.py +435 -0
  106. hackagent/cli/utils.py +276 -0
  107. hackagent/client.py +286 -0
  108. hackagent/errors.py +37 -0
  109. hackagent/logger.py +83 -0
  110. hackagent/models/__init__.py +109 -0
  111. hackagent/models/agent.py +223 -0
  112. hackagent/models/agent_request.py +129 -0
  113. hackagent/models/api_token_log.py +184 -0
  114. hackagent/models/attack.py +154 -0
  115. hackagent/models/attack_request.py +82 -0
  116. hackagent/models/checkout_session_request_request.py +76 -0
  117. hackagent/models/checkout_session_response.py +59 -0
  118. hackagent/models/choice.py +81 -0
  119. hackagent/models/choice_message.py +67 -0
  120. hackagent/models/evaluation_status_enum.py +14 -0
  121. hackagent/models/generate_error_response.py +59 -0
  122. hackagent/models/generate_request_request.py +212 -0
  123. hackagent/models/generate_success_response.py +115 -0
  124. hackagent/models/generic_error_response.py +70 -0
  125. hackagent/models/message_request.py +67 -0
  126. hackagent/models/organization.py +102 -0
  127. hackagent/models/organization_minimal.py +68 -0
  128. hackagent/models/organization_request.py +71 -0
  129. hackagent/models/paginated_agent_list.py +123 -0
  130. hackagent/models/paginated_api_token_log_list.py +123 -0
  131. hackagent/models/paginated_attack_list.py +123 -0
  132. hackagent/models/paginated_organization_list.py +123 -0
  133. hackagent/models/paginated_prompt_list.py +123 -0
  134. hackagent/models/paginated_result_list.py +123 -0
  135. hackagent/models/paginated_run_list.py +123 -0
  136. hackagent/models/paginated_user_api_key_list.py +123 -0
  137. hackagent/models/paginated_user_profile_list.py +123 -0
  138. hackagent/models/patched_agent_request.py +128 -0
  139. hackagent/models/patched_attack_request.py +92 -0
  140. hackagent/models/patched_organization_request.py +71 -0
  141. hackagent/models/patched_prompt_request.py +125 -0
  142. hackagent/models/patched_result_request.py +237 -0
  143. hackagent/models/patched_run_request.py +138 -0
  144. hackagent/models/patched_user_profile_request.py +99 -0
  145. hackagent/models/prompt.py +220 -0
  146. hackagent/models/prompt_request.py +126 -0
  147. hackagent/models/result.py +294 -0
  148. hackagent/models/result_list_evaluation_status.py +14 -0
  149. hackagent/models/result_request.py +232 -0
  150. hackagent/models/run.py +233 -0
  151. hackagent/models/run_list_status.py +12 -0
  152. hackagent/models/run_request.py +133 -0
  153. hackagent/models/status_enum.py +12 -0
  154. hackagent/models/step_type_enum.py +14 -0
  155. hackagent/models/trace.py +121 -0
  156. hackagent/models/trace_request.py +94 -0
  157. hackagent/models/usage.py +75 -0
  158. hackagent/models/user_api_key.py +201 -0
  159. hackagent/models/user_api_key_request.py +73 -0
  160. hackagent/models/user_profile.py +135 -0
  161. hackagent/models/user_profile_minimal.py +76 -0
  162. hackagent/models/user_profile_request.py +99 -0
  163. hackagent/router/__init__.py +25 -0
  164. hackagent/router/adapters/__init__.py +20 -0
  165. hackagent/router/adapters/base.py +63 -0
  166. hackagent/router/adapters/google_adk.py +671 -0
  167. hackagent/router/adapters/litellm_adapter.py +524 -0
  168. hackagent/router/adapters/openai_adapter.py +426 -0
  169. hackagent/router/router.py +969 -0
  170. hackagent/router/types.py +54 -0
  171. hackagent/tracking/__init__.py +42 -0
  172. hackagent/tracking/context.py +163 -0
  173. hackagent/tracking/decorators.py +299 -0
  174. hackagent/tracking/tracker.py +441 -0
  175. hackagent/types.py +54 -0
  176. hackagent/utils.py +194 -0
  177. hackagent/vulnerabilities/__init__.py +13 -0
  178. hackagent/vulnerabilities/prompts.py +81 -0
  179. hackagent-0.3.1.dist-info/METADATA +122 -0
  180. hackagent-0.3.1.dist-info/RECORD +183 -0
  181. hackagent-0.3.1.dist-info/WHEEL +4 -0
  182. hackagent-0.3.1.dist-info/entry_points.txt +2 -0
  183. hackagent-0.3.1.dist-info/licenses/LICENSE +202 -0
hackagent/__init__.py ADDED
@@ -0,0 +1,12 @@
1
+ """A client library for accessing HackAgent API"""
2
+
3
+ from .agent import HackAgent
4
+ from .client import AuthenticatedClient, Client
5
+ from .router.types import AgentTypeEnum
6
+
7
+ __all__ = (
8
+ "AgentTypeEnum",
9
+ "AuthenticatedClient",
10
+ "Client",
11
+ "HackAgent",
12
+ )
hackagent/agent.py ADDED
@@ -0,0 +1,214 @@
1
+ # Copyright 2025 - AI4I. All rights reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ import logging
16
+ from typing import Any, Dict, Optional, Union
17
+
18
+ from hackagent import utils
19
+ from hackagent.attacks.strategies import AdvPrefix, AttackStrategy
20
+ from hackagent.client import AuthenticatedClient
21
+ from hackagent.errors import HackAgentError
22
+ from hackagent.router import AgentRouter
23
+ from hackagent.router.types import AgentTypeEnum
24
+ from hackagent.vulnerabilities.prompts import DEFAULT_PROMPTS
25
+
26
+ logger = logging.getLogger(__name__)
27
+
28
+
29
+ class HackAgent:
30
+ """
31
+ The primary client for orchestrating security assessments with HackAgent.
32
+
33
+ This class serves as the main entry point to the HackAgent library, providing
34
+ a high-level interface for:
35
+ - Configuring victim agents that will be assessed.
36
+ - Defining and selecting attack strategies.
37
+ - Executing automated security tests against the configured agents.
38
+ - Retrieving and handling test results.
39
+
40
+ It encapsulates complexities such as API authentication, agent registration
41
+ with the backend (via `AgentRouter`), and the dynamic dispatch of various
42
+ attack methodologies.
43
+
44
+ Attributes:
45
+ client: An `AuthenticatedClient` instance for API communication.
46
+ prompts: A dictionary of default prompts. This dictionary is a copy of
47
+ `DEFAULT_PROMPTS` and can be modified after instantiation if needed,
48
+ though the primary mechanism for custom prompts is usually via attack
49
+ configurations.
50
+ router: An `AgentRouter` instance managing the agent's representation
51
+ in the HackAgent backend.
52
+ attack_strategies: A dictionary mapping strategy names to their
53
+ `AttackStrategy` implementations.
54
+ """
55
+
56
+ def __init__(
57
+ self,
58
+ endpoint: str,
59
+ name: Optional[str] = None,
60
+ agent_type: Union[AgentTypeEnum, str] = AgentTypeEnum.UNKNOWN,
61
+ base_url: Optional[str] = None,
62
+ api_key: Optional[str] = None,
63
+ raise_on_unexpected_status: bool = False,
64
+ timeout: Optional[float] = None,
65
+ env_file_path: Optional[str] = None,
66
+ ):
67
+ """
68
+ Initializes the HackAgent client and prepares it for interaction.
69
+
70
+ This constructor sets up the authenticated API client, loads default
71
+ prompts, resolves the agent type, and initializes the agent router
72
+ to ensure the agent is known to the backend. It also prepares available
73
+ attack strategies.
74
+
75
+ Args:
76
+ endpoint: The target application's endpoint URL. This is the primary
77
+ interface that the configured agent will interact with or represent
78
+ during security tests.
79
+ name: An optional descriptive name for the agent being configured.
80
+ If not provided, a default name might be assigned or behavior might
81
+ depend on the specific backend agent management policies.
82
+ agent_type: Specifies the type of the agent. This can be provided
83
+ as an `AgentTypeEnum` member (e.g., `AgentTypeEnum.GOOGLE_ADK`) or
84
+ as a string identifier (e.g., "google-adk", "litellm").
85
+ String values are automatically converted to the corresponding
86
+ `AgentTypeEnum` member. Defaults to `AgentTypeEnum.UNKNOWN` if
87
+ not specified or if an invalid string is provided.
88
+ base_url: The base URL for the HackAgent API service.
89
+ api_key: The API key for authenticating with the HackAgent API.
90
+ If omitted, the client will attempt to retrieve it from the
91
+ `HACKAGENT_API_KEY` environment variable. The `env_file_path`
92
+ parameter can specify a .env file to load this variable from.
93
+ raise_on_unexpected_status: If set to `True`, the API client will
94
+ raise an exception for any HTTP status codes that are not typically
95
+ expected for a successful operation. Defaults to `False`.
96
+ timeout: The timeout duration in seconds for API requests made by the
97
+ authenticated client. Defaults to `None` (which might mean a
98
+ default timeout from the underlying HTTP library is used).
99
+ env_file_path: An optional path to a .env file. If provided, environment
100
+ variables (such as `HACKAGENT_API_KEY`) will be loaded from this
101
+ file if not already present in the environment.
102
+ """
103
+
104
+ resolved_auth_token = utils.resolve_api_token(
105
+ direct_api_key_param=api_key, env_file_path=env_file_path
106
+ )
107
+
108
+ self.client = AuthenticatedClient(
109
+ base_url=base_url,
110
+ token=resolved_auth_token,
111
+ prefix="Bearer",
112
+ raise_on_unexpected_status=raise_on_unexpected_status,
113
+ timeout=timeout,
114
+ )
115
+
116
+ self.prompts = DEFAULT_PROMPTS.copy()
117
+
118
+ processed_agent_type = utils.resolve_agent_type(agent_type)
119
+
120
+ self.router = AgentRouter(
121
+ client=self.client,
122
+ name=name,
123
+ agent_type=processed_agent_type,
124
+ endpoint=endpoint,
125
+ )
126
+
127
+ self.attack_strategies: Dict[str, AttackStrategy] = {
128
+ "advprefix": AdvPrefix(hack_agent=self),
129
+ }
130
+
131
+ def hack(
132
+ self,
133
+ attack_config: Dict[str, Any],
134
+ run_config_override: Optional[Dict[str, Any]] = None,
135
+ fail_on_run_error: bool = True,
136
+ _tui_app: Optional[Any] = None,
137
+ _tui_log_callback: Optional[Any] = None,
138
+ ) -> Any:
139
+ """
140
+ Executes a specified attack strategy against the configured victim agent.
141
+
142
+ This method serves as the primary action command for initiating an attack.
143
+ It identifies the appropriate attack strategy based on `attack_config`,
144
+ ensures the victim agent (managed by `self.router`) is ready, and then
145
+ delegates the execution to the chosen strategy.
146
+
147
+ Args:
148
+ attack_config: A dictionary containing parameters specific to the
149
+ chosen attack type. Must include an 'attack_type' key that maps
150
+ to a registered strategy (e.g., "advprefix"). Other keys provide
151
+ configuration for that strategy (e.g., 'category', 'prompt_text').
152
+ run_config_override: An optional dictionary that can override default
153
+ run configurations. The specifics depend on the attack strategy
154
+ and backend capabilities.
155
+ fail_on_run_error: If `True` (the default), an exception will be
156
+ raised if the attack run encounters an error and fails. If `False`,
157
+ errors might be suppressed or handled differently by the strategy.
158
+
159
+ Returns:
160
+ The result returned by the `execute` method of the chosen attack
161
+ strategy. The nature of this result is strategy-dependent.
162
+
163
+ Raises:
164
+ ValueError: If the 'attack_type' is missing from `attack_config` or
165
+ if the specified 'attack_type' is not a supported/registered
166
+ strategy.
167
+ HackAgentError: For issues during API interaction, problems with backend
168
+ agent operations, or other unexpected errors during the attack process.
169
+ """
170
+ try:
171
+ attack_type = attack_config.get("attack_type")
172
+ if not attack_type:
173
+ raise ValueError("'attack_type' must be provided in attack_config.")
174
+
175
+ strategy = self.attack_strategies.get(attack_type)
176
+ if not strategy:
177
+ supported_types = list(self.attack_strategies.keys())
178
+ raise ValueError(
179
+ f"Unsupported attack_type: {attack_type}. Supported types: {supported_types}."
180
+ )
181
+
182
+ backend_agent = self.router.backend_agent
183
+
184
+ logger.info(
185
+ f"Preparing to attack agent '{backend_agent.name}' "
186
+ f"(ID: {backend_agent.id}, Type: {backend_agent.agent_type}) "
187
+ f"configured in this HackAgent instance, using strategy '{attack_type}'."
188
+ )
189
+
190
+ return strategy.execute(
191
+ attack_config=attack_config,
192
+ run_config_override=run_config_override,
193
+ fail_on_run_error=fail_on_run_error,
194
+ _tui_app=_tui_app,
195
+ _tui_log_callback=_tui_log_callback,
196
+ )
197
+
198
+ except HackAgentError:
199
+ raise
200
+ except ValueError as ve:
201
+ logger.error(f"Configuration error in HackAgent.hack: {ve}", exc_info=True)
202
+ raise HackAgentError(f"Configuration error: {ve}") from ve
203
+ except RuntimeError as re:
204
+ logger.error(f"Runtime error during HackAgent.hack: {re}", exc_info=True)
205
+ if "Failed to create backend agent" in str(
206
+ re
207
+ ) or "Failed to update metadata" in str(re):
208
+ raise HackAgentError(f"Backend agent operation failed: {re}") from re
209
+ raise HackAgentError(f"An unexpected runtime error occurred: {re}") from re
210
+ except Exception as e:
211
+ logger.error(f"Unexpected error in HackAgent.hack: {e}", exc_info=True)
212
+ raise HackAgentError(
213
+ f"An unexpected error occurred during attack: {e}"
214
+ ) from e
@@ -0,0 +1 @@
1
+ """Contains methods for accessing the API"""
@@ -0,0 +1 @@
1
+ """Contains endpoint functions for accessing the API"""
@@ -0,0 +1,347 @@
1
+ from http import HTTPStatus
2
+ from typing import Any, Optional, Union
3
+
4
+ import httpx
5
+
6
+ from ... import errors
7
+ from ...client import AuthenticatedClient, Client
8
+ from ...models.agent import Agent
9
+ from ...models.agent_request import AgentRequest
10
+ from ...types import Response
11
+
12
+
13
+ def _get_kwargs(
14
+ *,
15
+ body: AgentRequest,
16
+ ) -> dict[str, Any]:
17
+ headers: dict[str, Any] = {}
18
+
19
+ _kwargs: dict[str, Any] = {
20
+ "method": "post",
21
+ "url": "/agent",
22
+ }
23
+
24
+ _kwargs["json"] = body.to_dict()
25
+
26
+ headers["Content-Type"] = "application/json"
27
+
28
+ _kwargs["headers"] = headers
29
+ return _kwargs
30
+
31
+
32
+ def _parse_response(
33
+ *, client: Union[AuthenticatedClient, Client], response: httpx.Response
34
+ ) -> Optional[Agent]:
35
+ if response.status_code == 201:
36
+ response_201 = Agent.from_dict(response.json())
37
+
38
+ return response_201
39
+ if client.raise_on_unexpected_status:
40
+ raise errors.UnexpectedStatus(response.status_code, response.content)
41
+ else:
42
+ return None
43
+
44
+
45
+ def _build_response(
46
+ *, client: Union[AuthenticatedClient, Client], response: httpx.Response
47
+ ) -> Response[Agent]:
48
+ return Response(
49
+ status_code=HTTPStatus(response.status_code),
50
+ content=response.content,
51
+ headers=response.headers,
52
+ parsed=_parse_response(client=client, response=response),
53
+ )
54
+
55
+
56
+ def sync_detailed(
57
+ *,
58
+ client: AuthenticatedClient,
59
+ body: AgentRequest,
60
+ ) -> Response[Agent]:
61
+ """Provides CRUD operations for Agent instances.
62
+
63
+ This ViewSet manages Agent records, ensuring that users can only interact
64
+ with agents based on their permissions and organizational context.
65
+ It filters agent listings for users and handles the logic for creating
66
+ agents, including associating them with the correct organization and owner.
67
+
68
+ SDK-primary endpoint - API Key authentication is recommended for programmatic access.
69
+ Auth0 authentication is supported as fallback for web dashboard use.
70
+
71
+ Permissions are based on IsAuthenticated, with queryset filtering providing
72
+ row-level access control.
73
+
74
+ Class Attributes:
75
+ queryset (QuerySet): The default queryset for listing agents, initially all agents.
76
+ This is further filtered by `get_queryset()`.
77
+ serializer_class (AgentSerializer): The serializer used for validating and
78
+ deserializing input, and for serializing output.
79
+ authentication_classes (list): API Key (primary) + Auth0 (fallback) authentication.
80
+ permission_classes (list): List of permission classes to use.
81
+ parser_classes (list): List of parser classes for handling request data.
82
+ lookup_field (str): The model field used for looking up individual instances (UUID 'id').
83
+
84
+ Args:
85
+ body (AgentRequest): Serializes Agent model instances to JSON and validates data for
86
+ creating
87
+ or updating Agent instances.
88
+
89
+ This serializer provides a comprehensive representation of an Agent,
90
+ including its type, endpoint, and nested details for related 'organization'
91
+ and 'owner' for read operations, while allowing 'organization' and 'owner' IDs
92
+ for write operations.
93
+
94
+ Attributes:
95
+ organization_detail (OrganizationMinimalSerializer): Read-only nested
96
+ serializer for the agent's organization. Displays minimal details.
97
+ owner_detail (UserProfileMinimalSerializer): Read-only nested serializer
98
+ for the agent's owner's user profile. Displays minimal details.
99
+ Can be null if the agent has no owner or the owner has no profile.
100
+ agent_type (CharField): The type of the agent as a string
101
+ (e.g., LITELLM, OPENAI_SDK, GOOGLE_ADK).
102
+
103
+ Meta:
104
+ model (Agent): The model class that this serializer works with.
105
+ fields (tuple): The fields to include in the serialized output.
106
+ Includes standard Agent fields like 'endpoint', 'type',
107
+ and the read-only nested details.
108
+ read_only_fields (tuple): Fields that are read-only and cannot be
109
+ set during create/update operations through this serializer.
110
+ This includes 'id', 'created_at', 'updated_at', and the
111
+ nested detail fields.
112
+
113
+ Raises:
114
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
115
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
116
+
117
+ Returns:
118
+ Response[Agent]
119
+ """
120
+
121
+ kwargs = _get_kwargs(
122
+ body=body,
123
+ )
124
+
125
+ response = client.get_httpx_client().request(
126
+ **kwargs,
127
+ )
128
+
129
+ return _build_response(client=client, response=response)
130
+
131
+
132
+ def sync(
133
+ *,
134
+ client: AuthenticatedClient,
135
+ body: AgentRequest,
136
+ ) -> Optional[Agent]:
137
+ """Provides CRUD operations for Agent instances.
138
+
139
+ This ViewSet manages Agent records, ensuring that users can only interact
140
+ with agents based on their permissions and organizational context.
141
+ It filters agent listings for users and handles the logic for creating
142
+ agents, including associating them with the correct organization and owner.
143
+
144
+ SDK-primary endpoint - API Key authentication is recommended for programmatic access.
145
+ Auth0 authentication is supported as fallback for web dashboard use.
146
+
147
+ Permissions are based on IsAuthenticated, with queryset filtering providing
148
+ row-level access control.
149
+
150
+ Class Attributes:
151
+ queryset (QuerySet): The default queryset for listing agents, initially all agents.
152
+ This is further filtered by `get_queryset()`.
153
+ serializer_class (AgentSerializer): The serializer used for validating and
154
+ deserializing input, and for serializing output.
155
+ authentication_classes (list): API Key (primary) + Auth0 (fallback) authentication.
156
+ permission_classes (list): List of permission classes to use.
157
+ parser_classes (list): List of parser classes for handling request data.
158
+ lookup_field (str): The model field used for looking up individual instances (UUID 'id').
159
+
160
+ Args:
161
+ body (AgentRequest): Serializes Agent model instances to JSON and validates data for
162
+ creating
163
+ or updating Agent instances.
164
+
165
+ This serializer provides a comprehensive representation of an Agent,
166
+ including its type, endpoint, and nested details for related 'organization'
167
+ and 'owner' for read operations, while allowing 'organization' and 'owner' IDs
168
+ for write operations.
169
+
170
+ Attributes:
171
+ organization_detail (OrganizationMinimalSerializer): Read-only nested
172
+ serializer for the agent's organization. Displays minimal details.
173
+ owner_detail (UserProfileMinimalSerializer): Read-only nested serializer
174
+ for the agent's owner's user profile. Displays minimal details.
175
+ Can be null if the agent has no owner or the owner has no profile.
176
+ agent_type (CharField): The type of the agent as a string
177
+ (e.g., LITELLM, OPENAI_SDK, GOOGLE_ADK).
178
+
179
+ Meta:
180
+ model (Agent): The model class that this serializer works with.
181
+ fields (tuple): The fields to include in the serialized output.
182
+ Includes standard Agent fields like 'endpoint', 'type',
183
+ and the read-only nested details.
184
+ read_only_fields (tuple): Fields that are read-only and cannot be
185
+ set during create/update operations through this serializer.
186
+ This includes 'id', 'created_at', 'updated_at', and the
187
+ nested detail fields.
188
+
189
+ Raises:
190
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
191
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
192
+
193
+ Returns:
194
+ Agent
195
+ """
196
+
197
+ return sync_detailed(
198
+ client=client,
199
+ body=body,
200
+ ).parsed
201
+
202
+
203
+ async def asyncio_detailed(
204
+ *,
205
+ client: AuthenticatedClient,
206
+ body: AgentRequest,
207
+ ) -> Response[Agent]:
208
+ """Provides CRUD operations for Agent instances.
209
+
210
+ This ViewSet manages Agent records, ensuring that users can only interact
211
+ with agents based on their permissions and organizational context.
212
+ It filters agent listings for users and handles the logic for creating
213
+ agents, including associating them with the correct organization and owner.
214
+
215
+ SDK-primary endpoint - API Key authentication is recommended for programmatic access.
216
+ Auth0 authentication is supported as fallback for web dashboard use.
217
+
218
+ Permissions are based on IsAuthenticated, with queryset filtering providing
219
+ row-level access control.
220
+
221
+ Class Attributes:
222
+ queryset (QuerySet): The default queryset for listing agents, initially all agents.
223
+ This is further filtered by `get_queryset()`.
224
+ serializer_class (AgentSerializer): The serializer used for validating and
225
+ deserializing input, and for serializing output.
226
+ authentication_classes (list): API Key (primary) + Auth0 (fallback) authentication.
227
+ permission_classes (list): List of permission classes to use.
228
+ parser_classes (list): List of parser classes for handling request data.
229
+ lookup_field (str): The model field used for looking up individual instances (UUID 'id').
230
+
231
+ Args:
232
+ body (AgentRequest): Serializes Agent model instances to JSON and validates data for
233
+ creating
234
+ or updating Agent instances.
235
+
236
+ This serializer provides a comprehensive representation of an Agent,
237
+ including its type, endpoint, and nested details for related 'organization'
238
+ and 'owner' for read operations, while allowing 'organization' and 'owner' IDs
239
+ for write operations.
240
+
241
+ Attributes:
242
+ organization_detail (OrganizationMinimalSerializer): Read-only nested
243
+ serializer for the agent's organization. Displays minimal details.
244
+ owner_detail (UserProfileMinimalSerializer): Read-only nested serializer
245
+ for the agent's owner's user profile. Displays minimal details.
246
+ Can be null if the agent has no owner or the owner has no profile.
247
+ agent_type (CharField): The type of the agent as a string
248
+ (e.g., LITELLM, OPENAI_SDK, GOOGLE_ADK).
249
+
250
+ Meta:
251
+ model (Agent): The model class that this serializer works with.
252
+ fields (tuple): The fields to include in the serialized output.
253
+ Includes standard Agent fields like 'endpoint', 'type',
254
+ and the read-only nested details.
255
+ read_only_fields (tuple): Fields that are read-only and cannot be
256
+ set during create/update operations through this serializer.
257
+ This includes 'id', 'created_at', 'updated_at', and the
258
+ nested detail fields.
259
+
260
+ Raises:
261
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
262
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
263
+
264
+ Returns:
265
+ Response[Agent]
266
+ """
267
+
268
+ kwargs = _get_kwargs(
269
+ body=body,
270
+ )
271
+
272
+ response = await client.get_async_httpx_client().request(**kwargs)
273
+
274
+ return _build_response(client=client, response=response)
275
+
276
+
277
+ async def asyncio(
278
+ *,
279
+ client: AuthenticatedClient,
280
+ body: AgentRequest,
281
+ ) -> Optional[Agent]:
282
+ """Provides CRUD operations for Agent instances.
283
+
284
+ This ViewSet manages Agent records, ensuring that users can only interact
285
+ with agents based on their permissions and organizational context.
286
+ It filters agent listings for users and handles the logic for creating
287
+ agents, including associating them with the correct organization and owner.
288
+
289
+ SDK-primary endpoint - API Key authentication is recommended for programmatic access.
290
+ Auth0 authentication is supported as fallback for web dashboard use.
291
+
292
+ Permissions are based on IsAuthenticated, with queryset filtering providing
293
+ row-level access control.
294
+
295
+ Class Attributes:
296
+ queryset (QuerySet): The default queryset for listing agents, initially all agents.
297
+ This is further filtered by `get_queryset()`.
298
+ serializer_class (AgentSerializer): The serializer used for validating and
299
+ deserializing input, and for serializing output.
300
+ authentication_classes (list): API Key (primary) + Auth0 (fallback) authentication.
301
+ permission_classes (list): List of permission classes to use.
302
+ parser_classes (list): List of parser classes for handling request data.
303
+ lookup_field (str): The model field used for looking up individual instances (UUID 'id').
304
+
305
+ Args:
306
+ body (AgentRequest): Serializes Agent model instances to JSON and validates data for
307
+ creating
308
+ or updating Agent instances.
309
+
310
+ This serializer provides a comprehensive representation of an Agent,
311
+ including its type, endpoint, and nested details for related 'organization'
312
+ and 'owner' for read operations, while allowing 'organization' and 'owner' IDs
313
+ for write operations.
314
+
315
+ Attributes:
316
+ organization_detail (OrganizationMinimalSerializer): Read-only nested
317
+ serializer for the agent's organization. Displays minimal details.
318
+ owner_detail (UserProfileMinimalSerializer): Read-only nested serializer
319
+ for the agent's owner's user profile. Displays minimal details.
320
+ Can be null if the agent has no owner or the owner has no profile.
321
+ agent_type (CharField): The type of the agent as a string
322
+ (e.g., LITELLM, OPENAI_SDK, GOOGLE_ADK).
323
+
324
+ Meta:
325
+ model (Agent): The model class that this serializer works with.
326
+ fields (tuple): The fields to include in the serialized output.
327
+ Includes standard Agent fields like 'endpoint', 'type',
328
+ and the read-only nested details.
329
+ read_only_fields (tuple): Fields that are read-only and cannot be
330
+ set during create/update operations through this serializer.
331
+ This includes 'id', 'created_at', 'updated_at', and the
332
+ nested detail fields.
333
+
334
+ Raises:
335
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
336
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
337
+
338
+ Returns:
339
+ Agent
340
+ """
341
+
342
+ return (
343
+ await asyncio_detailed(
344
+ client=client,
345
+ body=body,
346
+ )
347
+ ).parsed