aixtools 0.3.3__tar.gz → 0.3.5__tar.gz

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.

Potentially problematic release.


This version of aixtools might be problematic. Click here for more details.

Files changed (103) hide show
  1. {aixtools-0.3.3 → aixtools-0.3.5}/PKG-INFO +1 -1
  2. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/_version.py +3 -3
  3. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/a2a/app.py +20 -0
  4. aixtools-0.3.5/aixtools/a2a/auth_middleware.py +46 -0
  5. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/auth/auth.py +4 -2
  6. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/testing/aix_test_model.py +39 -8
  7. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools.egg-info/SOURCES.txt +1 -0
  8. {aixtools-0.3.3 → aixtools-0.3.5}/README.md +0 -0
  9. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/.chainlit/config.toml +0 -0
  10. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/.chainlit/translations/bn.json +0 -0
  11. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/.chainlit/translations/en-US.json +0 -0
  12. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/.chainlit/translations/gu.json +0 -0
  13. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/.chainlit/translations/he-IL.json +0 -0
  14. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/.chainlit/translations/hi.json +0 -0
  15. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/.chainlit/translations/ja.json +0 -0
  16. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/.chainlit/translations/kn.json +0 -0
  17. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/.chainlit/translations/ml.json +0 -0
  18. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/.chainlit/translations/mr.json +0 -0
  19. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/.chainlit/translations/nl.json +0 -0
  20. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/.chainlit/translations/ta.json +0 -0
  21. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/.chainlit/translations/te.json +0 -0
  22. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/.chainlit/translations/zh-CN.json +0 -0
  23. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/__init__.py +0 -0
  24. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/a2a/google_sdk/__init__.py +0 -0
  25. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/a2a/google_sdk/pydantic_ai_adapter/agent_executor.py +0 -0
  26. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/a2a/google_sdk/pydantic_ai_adapter/storage.py +0 -0
  27. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/a2a/google_sdk/remote_agent_connection.py +0 -0
  28. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/a2a/google_sdk/utils.py +0 -0
  29. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/a2a/utils.py +0 -0
  30. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/agents/__init__.py +0 -0
  31. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/agents/agent.py +0 -0
  32. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/agents/agent_batch.py +0 -0
  33. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/agents/nodes_to_md.py +0 -0
  34. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/agents/nodes_to_message.py +0 -0
  35. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/agents/nodes_to_str.py +0 -0
  36. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/agents/print_nodes.py +0 -0
  37. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/agents/prompt.py +0 -0
  38. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/app.py +0 -0
  39. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/auth/__init__.py +0 -0
  40. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/chainlit.md +0 -0
  41. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/compliance/__init__.py +0 -0
  42. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/compliance/private_data.py +0 -0
  43. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/context.py +0 -0
  44. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/db/__init__.py +0 -0
  45. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/db/database.py +0 -0
  46. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/db/vector_db.py +0 -0
  47. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/evals/__init__.py +0 -0
  48. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/evals/__main__.py +0 -0
  49. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/evals/dataset.py +0 -0
  50. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/evals/discovery.py +0 -0
  51. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/evals/run_evals.py +0 -0
  52. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/google/client.py +0 -0
  53. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/log_view/__init__.py +0 -0
  54. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/log_view/app.py +0 -0
  55. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/log_view/display.py +0 -0
  56. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/log_view/export.py +0 -0
  57. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/log_view/filters.py +0 -0
  58. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/log_view/log_utils.py +0 -0
  59. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/log_view/node_summary.py +0 -0
  60. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/logfilters/__init__.py +0 -0
  61. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/logfilters/context_filter.py +0 -0
  62. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/logging/__init__.py +0 -0
  63. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/logging/log_objects.py +0 -0
  64. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/logging/logging_config.py +0 -0
  65. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/logging/mcp_log_models.py +0 -0
  66. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/logging/mcp_logger.py +0 -0
  67. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/logging/model_patch_logging.py +0 -0
  68. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/logging/open_telemetry.py +0 -0
  69. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/mcp/__init__.py +0 -0
  70. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/mcp/client.py +0 -0
  71. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/mcp/example_client.py +0 -0
  72. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/mcp/example_server.py +0 -0
  73. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/mcp/exceptions.py +0 -0
  74. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/mcp/fast_mcp_log.py +0 -0
  75. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/mcp/faulty_mcp.py +0 -0
  76. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/mcp/middleware.py +0 -0
  77. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/mcp/server.py +0 -0
  78. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/model_patch/model_patch.py +0 -0
  79. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/server/__init__.py +0 -0
  80. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/server/app_mounter.py +0 -0
  81. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/server/path.py +0 -0
  82. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/server/utils.py +0 -0
  83. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/testing/__init__.py +0 -0
  84. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/testing/agent_mock.py +0 -0
  85. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/testing/mock_tool.py +0 -0
  86. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/testing/model_patch_cache.py +0 -0
  87. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/tools/doctor/__init__.py +0 -0
  88. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/tools/doctor/mcp_tool_doctor.py +0 -0
  89. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/tools/doctor/tool_doctor.py +0 -0
  90. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/tools/doctor/tool_recommendation.py +0 -0
  91. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/utils/__init__.py +0 -0
  92. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/utils/chainlit/cl_agent_show.py +0 -0
  93. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/utils/chainlit/cl_utils.py +0 -0
  94. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/utils/config.py +0 -0
  95. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/utils/config_util.py +0 -0
  96. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/utils/enum_with_description.py +0 -0
  97. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/utils/files.py +0 -0
  98. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/utils/persisted_dict.py +0 -0
  99. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/utils/utils.py +0 -0
  100. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/vault/__init__.py +0 -0
  101. {aixtools-0.3.3 → aixtools-0.3.5}/aixtools/vault/vault.py +0 -0
  102. {aixtools-0.3.3 → aixtools-0.3.5}/pyproject.toml +0 -0
  103. {aixtools-0.3.3 → aixtools-0.3.5}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aixtools
3
- Version: 0.3.3
3
+ Version: 0.3.5
4
4
  Summary: Tools for AI exploration and debugging
5
5
  Requires-Python: >=3.11.2
6
6
  Description-Content-Type: text/markdown
@@ -28,7 +28,7 @@ version_tuple: VERSION_TUPLE
28
28
  commit_id: COMMIT_ID
29
29
  __commit_id__: COMMIT_ID
30
30
 
31
- __version__ = version = '0.3.3'
32
- __version_tuple__ = version_tuple = (0, 3, 3)
31
+ __version__ = version = '0.3.5'
32
+ __version_tuple__ = version_tuple = (0, 3, 5)
33
33
 
34
- __commit_id__ = commit_id = 'g7da95a013'
34
+ __commit_id__ = commit_id = 'g9eb31448f'
@@ -6,6 +6,9 @@ import json
6
6
  from functools import partial
7
7
  from typing import assert_never
8
8
 
9
+ from a2a.server.apps import A2AStarletteApplication
10
+ from a2a.server.request_handlers import RequestHandler
11
+ from a2a.types import AgentCard
9
12
  from fasta2a.applications import FastA2A
10
13
  from fasta2a.broker import InMemoryBroker
11
14
  from fasta2a.schema import Part, TaskSendParams
@@ -26,6 +29,8 @@ from starlette.exceptions import HTTPException
26
29
  from starlette.requests import Request
27
30
  from starlette.responses import RedirectResponse
28
31
 
32
+ from aixtools.a2a.auth_middleware import AuthMiddleware
33
+ from aixtools.auth.auth import AccessTokenAuthProvider
29
34
  from aixtools.context import session_id_var, user_id_var
30
35
 
31
36
 
@@ -124,3 +129,18 @@ def fix_a2a_docs_pages(app: Starlette) -> None:
124
129
 
125
130
  app.router.add_route("/.well-known/agent.json", redirect_to_sub_agent, methods=["GET"])
126
131
  app.router.add_route("/", redirect_to_sub_agent, methods=["POST"])
132
+
133
+
134
+ def build_a2a_starlette_app(
135
+ public_agent_card: AgentCard, request_handler: RequestHandler, auth_provider: AccessTokenAuthProvider | None = None
136
+ ) -> Starlette:
137
+ """Builds a A2AStarletteApplication with the given auth provider."""
138
+ server = A2AStarletteApplication(
139
+ agent_card=public_agent_card,
140
+ http_handler=request_handler,
141
+ )
142
+
143
+ app = server.build()
144
+ if auth_provider:
145
+ app.add_middleware(AuthMiddleware, provider=auth_provider)
146
+ return app
@@ -0,0 +1,46 @@
1
+ "Auth module managing user authentication for A2A server"
2
+
3
+ from logging import getLogger
4
+
5
+ from starlette.middleware.base import BaseHTTPMiddleware
6
+ from starlette.requests import Request
7
+
8
+ from aixtools.auth.auth import AccessTokenAuthProvider, AuthTokenError
9
+ from aixtools.utils import config
10
+
11
+ logger = getLogger(__name__)
12
+
13
+
14
+ class AuthMiddleware(BaseHTTPMiddleware): # pylint: disable=too-few-public-methods
15
+ """
16
+ Middleware that enforces access token authentication for A2A route.
17
+ """
18
+
19
+ AGENT_CARD_PATH_SUFFIXES = [".well-known/agent.json", ".well-known/agent-card.json"]
20
+ APP_DEFAULT_SCOPE = config.APP_DEFAULT_SCOPE
21
+
22
+ def __init__(self, app, provider: AccessTokenAuthProvider):
23
+ super().__init__(app)
24
+ self.provider = provider
25
+
26
+ async def dispatch(self, request: Request, call_next):
27
+ """
28
+ Auth middleware function that checks whether the request has a valid access token.
29
+
30
+ :param request: The incoming http request
31
+ :param call_next: The next function in the chain
32
+ :raises HTTPException: If an access token isn't valid or missing
33
+ """
34
+
35
+ path = request.url.path
36
+
37
+ # allow agent cards to pass
38
+ if any(path.endswith(suffix) for suffix in self.AGENT_CARD_PATH_SUFFIXES):
39
+ return await call_next(request)
40
+
41
+ auth_header = request.headers.get("Authorization") or request.headers.get("authorization")
42
+ try:
43
+ await self.provider.verify_auth_header(auth_header)
44
+ return await call_next(request)
45
+ except AuthTokenError as e:
46
+ raise e.to_http_exception(self.APP_DEFAULT_SCOPE)
@@ -120,6 +120,7 @@ class AccessTokenVerifier:
120
120
  except InvalidSignatureError as e:
121
121
  raise AuthTokenError(AuthTokenErrorCode.INVALID_SIGNATURE) from e
122
122
  except jwt.exceptions.PyJWTError as e:
123
+ logger.exception("Unable to check JWT token: %s", token)
123
124
  raise AuthTokenError(AuthTokenErrorCode.JWT_ERROR) from e
124
125
 
125
126
  def authorize_claims(self, claims: dict, expected_scope: str):
@@ -148,10 +149,11 @@ class AccessTokenVerifier:
148
149
  logger.info("Authorized JWT token, against %s", groups)
149
150
  return
150
151
 
151
- logger.error("Could not find any group in JWT token, matching: %s", self.authorized_groups)
152
+ email = claims.get("email")
153
+ logger.warning("User %s group %s does not match configured groups %s", email, groups, self.authorized_groups)
152
154
  raise AuthTokenError(
153
155
  AuthTokenErrorCode.MISSING_GROUPS_ERROR,
154
- f"Could not find any group in JWT token, matching: {self.authorized_groups}",
156
+ f"User {email} group {groups} does not match configured groups {self.authorized_groups}",
155
157
  )
156
158
 
157
159
 
@@ -19,6 +19,20 @@ from ..utils.utils import async_iter
19
19
  FINAL_RESULT_TOOL_NAME = "final_result"
20
20
 
21
21
 
22
+ def _convert_to_parts(items: list[str | TextPart | ToolCallPart]) -> list[TextPart | ToolCallPart]:
23
+ """Convert a list of strings, TextParts, or ToolCallParts to a list of Parts."""
24
+ parts: list[TextPart | ToolCallPart] = []
25
+ for item in items:
26
+ match item:
27
+ case str():
28
+ parts.append(TextPart(item))
29
+ case TextPart() | ToolCallPart():
30
+ parts.append(item)
31
+ case _:
32
+ raise ValueError(f"Invalid item type in list: {type(item)}, item: {item}")
33
+ return parts
34
+
35
+
22
36
  def final_result_tool(result: BaseModel | dict) -> ToolCallPart:
23
37
  """Create a ToolCallPart for the final result."""
24
38
  if isinstance(result, BaseModel):
@@ -33,7 +47,11 @@ class AixTestModel(Model):
33
47
  Test model, returns a specified list of answers, including messages or tool calls
34
48
  This is used for testing the agent and model interaction with the rest of the system.
35
49
 
36
- responses: Is a list of strings or ToolCallPart objects that the model will return in order.
50
+ responses: Is a list of response items that the model will return in order. Each item can be:
51
+ - str: A simple text response
52
+ - TextPart: A text part
53
+ - ToolCallPart: A tool call
54
+ - list[str | TextPart | ToolCallPart]: Multiple parts in a single response
37
55
 
38
56
  Note: The agent will continue to invoke 'request()' until it returns a txt (i.e. not a ToolCallPart).
39
57
 
@@ -69,11 +87,25 @@ class AixTestModel(Model):
69
87
  ]
70
88
  )
71
89
  ```
90
+
91
+ Example with multiple parts in a single response:
92
+ ```
93
+ model = AixTestModel(
94
+ responses=[
95
+ [
96
+ "First, let me think about this...",
97
+ ToolCallPart(tool_name='analyze', args={'data': 'xyz'}),
98
+ TextPart("Analysis complete."),
99
+ ],
100
+ "Final answer after analysis.",
101
+ ]
102
+ )
103
+ ```
72
104
  """
73
105
 
74
106
  def __init__( # pylint: disable=super-init-not-called
75
107
  self,
76
- responses: list[str | TextPart | ToolCallPart] | AsyncGeneratorType,
108
+ responses: list[str | TextPart | ToolCallPart | list[str | TextPart | ToolCallPart]] | AsyncGeneratorType,
77
109
  sleep_time: float | None = None,
78
110
  ):
79
111
  self.response_iter = responses(self) if callable(responses) else async_iter(responses)
@@ -141,15 +173,14 @@ class AixTestModel(Model):
141
173
  if callable(res):
142
174
  res = res(self, messages)
143
175
  match res:
144
- case str():
145
- return ModelResponse(parts=[TextPart(res)], model_name=self.model_name)
146
- case ToolCallPart():
147
- return ModelResponse(parts=[res], model_name=self.model_name)
148
- case TextPart():
149
- return ModelResponse(parts=[res], model_name=self.model_name)
150
176
  case Exception():
151
177
  raise res
178
+ case list():
179
+ parts = _convert_to_parts(res)
180
+ case str() | TextPart() | ToolCallPart():
181
+ parts = _convert_to_parts([res])
152
182
  case _:
153
183
  raise ValueError(f"Invalid response type: {type(res)}, response: {res}")
154
184
  if self.sleep_time:
155
185
  await asyncio.sleep(self.sleep_time)
186
+ return ModelResponse(parts=parts, model_name=self.model_name)
@@ -20,6 +20,7 @@ aixtools/.chainlit/translations/ta.json
20
20
  aixtools/.chainlit/translations/te.json
21
21
  aixtools/.chainlit/translations/zh-CN.json
22
22
  aixtools/a2a/app.py
23
+ aixtools/a2a/auth_middleware.py
23
24
  aixtools/a2a/utils.py
24
25
  aixtools/a2a/google_sdk/__init__.py
25
26
  aixtools/a2a/google_sdk/remote_agent_connection.py
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes