agent-adapter 1.1.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.
Files changed (591) hide show
  1. agent_adapter/__init__.py +375 -0
  2. agent_adapter/__main__.py +5 -0
  3. agent_adapter/_guide/AGENTS.md +679 -0
  4. agent_adapter/_guide/llms-full.txt +1973 -0
  5. agent_adapter/_version.py +3 -0
  6. agent_adapter/approval/__init__.py +74 -0
  7. agent_adapter/approval/_records.py +99 -0
  8. agent_adapter/approval/batch.py +146 -0
  9. agent_adapter/approval/builtin.py +127 -0
  10. agent_adapter/approval/deferred.py +185 -0
  11. agent_adapter/approval/dynamodb_items.py +236 -0
  12. agent_adapter/approval/dynamodb_store.py +396 -0
  13. agent_adapter/approval/memory.py +167 -0
  14. agent_adapter/approval/persist.py +114 -0
  15. agent_adapter/approval/redis_scripts.py +88 -0
  16. agent_adapter/approval/redis_store.py +282 -0
  17. agent_adapter/approval/rules.py +329 -0
  18. agent_adapter/approval/sqlalchemy_schema.py +103 -0
  19. agent_adapter/approval/sqlalchemy_store.py +350 -0
  20. agent_adapter/approval/sqlite_store.py +380 -0
  21. agent_adapter/approval/store.py +285 -0
  22. agent_adapter/audit/__init__.py +28 -0
  23. agent_adapter/audit/_actions.py +148 -0
  24. agent_adapter/audit/_chain.py +89 -0
  25. agent_adapter/audit/_check.py +153 -0
  26. agent_adapter/audit/_files.py +181 -0
  27. agent_adapter/audit/_scrub.py +71 -0
  28. agent_adapter/audit/_writer.py +80 -0
  29. agent_adapter/audit/callable.py +81 -0
  30. agent_adapter/audit/errors.py +20 -0
  31. agent_adapter/audit/export.py +125 -0
  32. agent_adapter/audit/sink.py +178 -0
  33. agent_adapter/audit/store.py +305 -0
  34. agent_adapter/audit/verify.py +235 -0
  35. agent_adapter/cache/__init__.py +38 -0
  36. agent_adapter/cache/codec.py +63 -0
  37. agent_adapter/cache/keys.py +101 -0
  38. agent_adapter/cache/layout.py +55 -0
  39. agent_adapter/cache/llm_cache.py +95 -0
  40. agent_adapter/cache/memory.py +82 -0
  41. agent_adapter/cache/providers/__init__.py +16 -0
  42. agent_adapter/cache/providers/_base.py +129 -0
  43. agent_adapter/cache/providers/anthropic.py +158 -0
  44. agent_adapter/cache/providers/gemini.py +264 -0
  45. agent_adapter/cache/providers/openai.py +224 -0
  46. agent_adapter/cache/redis.py +138 -0
  47. agent_adapter/cache/tool_cache.py +95 -0
  48. agent_adapter/chat/__init__.py +11 -0
  49. agent_adapter/chat/contract.py +78 -0
  50. agent_adapter/cli/__init__.py +3 -0
  51. agent_adapter/cli/__main__.py +5 -0
  52. agent_adapter/cli/_migrate_diff.py +230 -0
  53. agent_adapter/cli/_migrate_rules.py +86 -0
  54. agent_adapter/cli/_migrate_scan.py +417 -0
  55. agent_adapter/cli/audit.py +108 -0
  56. agent_adapter/cli/doctor.py +177 -0
  57. agent_adapter/cli/doctor_features.py +156 -0
  58. agent_adapter/cli/eval.py +304 -0
  59. agent_adapter/cli/findings.py +21 -0
  60. agent_adapter/cli/guide.py +89 -0
  61. agent_adapter/cli/main.py +154 -0
  62. agent_adapter/cli/migrate.py +146 -0
  63. agent_adapter/cli/pipindex.py +130 -0
  64. agent_adapter/cli/policy.py +117 -0
  65. agent_adapter/cli/scaffold.py +102 -0
  66. agent_adapter/cli/templates/adk.py.tmpl +78 -0
  67. agent_adapter/cli/templates/agno.py.tmpl +66 -0
  68. agent_adapter/cli/templates/celery.py.tmpl +37 -0
  69. agent_adapter/cli/templates/crewai.py.tmpl +70 -0
  70. agent_adapter/cli/templates/fastapi.py.tmpl +30 -0
  71. agent_adapter/cli/templates/flask.py.tmpl +30 -0
  72. agent_adapter/cli/templates/langgraph.py.tmpl +36 -0
  73. agent_adapter/cli/templates/mcp_server.py.tmpl +29 -0
  74. agent_adapter/cli/templates/openai_agents.py.tmpl +28 -0
  75. agent_adapter/cli/templates/pydantic_ai.py.tmpl +68 -0
  76. agent_adapter/cli/templates/script.py.tmpl +21 -0
  77. agent_adapter/cli/templates/strands.py.tmpl +63 -0
  78. agent_adapter/cli/ui.py +298 -0
  79. agent_adapter/context/__init__.py +70 -0
  80. agent_adapter/context/compress.py +190 -0
  81. agent_adapter/context/conversation.py +168 -0
  82. agent_adapter/context/defaults.py +20 -0
  83. agent_adapter/context/entries.py +159 -0
  84. agent_adapter/context/formats/__init__.py +193 -0
  85. agent_adapter/context/formats/_items.py +164 -0
  86. agent_adapter/context/formats/_registry.py +77 -0
  87. agent_adapter/context/formats/_shared.py +287 -0
  88. agent_adapter/context/formats/anthropic.py +142 -0
  89. agent_adapter/context/formats/gemini.py +186 -0
  90. agent_adapter/context/formats/langchain.py +134 -0
  91. agent_adapter/context/formats/openai.py +234 -0
  92. agent_adapter/context/guard.py +240 -0
  93. agent_adapter/context/model.py +288 -0
  94. agent_adapter/context/neutralise.py +106 -0
  95. agent_adapter/context/policy.py +142 -0
  96. agent_adapter/context/recall.py +99 -0
  97. agent_adapter/context/redaction.py +106 -0
  98. agent_adapter/context/reference.py +24 -0
  99. agent_adapter/context/relevant.py +67 -0
  100. agent_adapter/context/rerank.py +211 -0
  101. agent_adapter/context/run.py +181 -0
  102. agent_adapter/context/scorer.py +132 -0
  103. agent_adapter/context/scoring.py +113 -0
  104. agent_adapter/context/shrink.py +87 -0
  105. agent_adapter/context/step.py +222 -0
  106. agent_adapter/context/steps.py +286 -0
  107. agent_adapter/context/summarize.py +332 -0
  108. agent_adapter/context/summary_call.py +136 -0
  109. agent_adapter/context/summary_prompt.py +157 -0
  110. agent_adapter/context/tokens.py +90 -0
  111. agent_adapter/core/__init__.py +1 -0
  112. agent_adapter/core/_attempt.py +22 -0
  113. agent_adapter/core/_bounded.py +36 -0
  114. agent_adapter/core/_default.py +28 -0
  115. agent_adapter/core/_docstring.py +53 -0
  116. agent_adapter/core/_nulls.py +101 -0
  117. agent_adapter/core/_partial_json.py +194 -0
  118. agent_adapter/core/_policy.py +111 -0
  119. agent_adapter/core/_signature.py +243 -0
  120. agent_adapter/core/callables.py +10 -0
  121. agent_adapter/core/context.py +54 -0
  122. agent_adapter/core/control.py +57 -0
  123. agent_adapter/core/error_base.py +47 -0
  124. agent_adapter/core/errors.py +399 -0
  125. agent_adapter/core/imported.py +124 -0
  126. agent_adapter/core/messages.py +185 -0
  127. agent_adapter/core/model_errors.py +100 -0
  128. agent_adapter/core/ports.py +90 -0
  129. agent_adapter/core/registry.py +221 -0
  130. agent_adapter/core/tool.py +360 -0
  131. agent_adapter/core/types.py +307 -0
  132. agent_adapter/cost/__init__.py +21 -0
  133. agent_adapter/cost/_table.py +233 -0
  134. agent_adapter/cost/ledger.py +189 -0
  135. agent_adapter/cost/prices.py +389 -0
  136. agent_adapter/cost/prices_default.json +153 -0
  137. agent_adapter/cost/sinks.py +88 -0
  138. agent_adapter/cost/summary.py +93 -0
  139. agent_adapter/embeddings/__init__.py +13 -0
  140. agent_adapter/embeddings/_record.py +215 -0
  141. agent_adapter/embeddings/cache.py +102 -0
  142. agent_adapter/embeddings/callable.py +241 -0
  143. agent_adapter/embeddings/port.py +52 -0
  144. agent_adapter/errors.py +117 -0
  145. agent_adapter/evals/__init__.py +175 -0
  146. agent_adapter/evals/_advisor_report.py +142 -0
  147. agent_adapter/evals/_calls.py +60 -0
  148. agent_adapter/evals/_collect.py +74 -0
  149. agent_adapter/evals/_grading.py +56 -0
  150. agent_adapter/evals/_render.py +101 -0
  151. agent_adapter/evals/_run_content.py +167 -0
  152. agent_adapter/evals/_run_files.py +180 -0
  153. agent_adapter/evals/_schema_check.py +100 -0
  154. agent_adapter/evals/_spend.py +224 -0
  155. agent_adapter/evals/_step_models.py +122 -0
  156. agent_adapter/evals/_text.py +50 -0
  157. agent_adapter/evals/advisor.py +399 -0
  158. agent_adapter/evals/cases.py +122 -0
  159. agent_adapter/evals/from_runs.py +222 -0
  160. agent_adapter/evals/graders.py +316 -0
  161. agent_adapter/evals/judge.py +146 -0
  162. agent_adapter/evals/model.py +53 -0
  163. agent_adapter/evals/pytest_plugin.py +64 -0
  164. agent_adapter/evals/report.py +228 -0
  165. agent_adapter/evals/runner.py +360 -0
  166. agent_adapter/evals/store.py +46 -0
  167. agent_adapter/evals/targets.py +218 -0
  168. agent_adapter/exec/__init__.py +48 -0
  169. agent_adapter/exec/_approve.py +211 -0
  170. agent_adapter/exec/_batches.py +195 -0
  171. agent_adapter/exec/_call_content.py +32 -0
  172. agent_adapter/exec/_call_steps.py +107 -0
  173. agent_adapter/exec/_canon.py +394 -0
  174. agent_adapter/exec/_durable.py +272 -0
  175. agent_adapter/exec/_durable_loop.py +228 -0
  176. agent_adapter/exec/_durable_seal.py +192 -0
  177. agent_adapter/exec/_journal.py +372 -0
  178. agent_adapter/exec/_loop_history.py +58 -0
  179. agent_adapter/exec/_loop_steps.py +261 -0
  180. agent_adapter/exec/_resume.py +183 -0
  181. agent_adapter/exec/_settings.py +53 -0
  182. agent_adapter/exec/_sink_hub.py +55 -0
  183. agent_adapter/exec/_sugar.py +297 -0
  184. agent_adapter/exec/_sync_twins.py +121 -0
  185. agent_adapter/exec/agents.py +249 -0
  186. agent_adapter/exec/args.py +12 -0
  187. agent_adapter/exec/checkpoints/__init__.py +31 -0
  188. agent_adapter/exec/checkpoints/_port.py +239 -0
  189. agent_adapter/exec/checkpoints/memory.py +104 -0
  190. agent_adapter/exec/checkpoints/redis_store.py +344 -0
  191. agent_adapter/exec/checkpoints/sqlalchemy_store.py +368 -0
  192. agent_adapter/exec/checkpoints/sqlite_store.py +324 -0
  193. agent_adapter/exec/control.py +5 -0
  194. agent_adapter/exec/defaults.py +123 -0
  195. agent_adapter/exec/executor.py +405 -0
  196. agent_adapter/exec/guards.py +278 -0
  197. agent_adapter/exec/handoffs.py +118 -0
  198. agent_adapter/exec/integration.py +52 -0
  199. agent_adapter/exec/parallel.py +279 -0
  200. agent_adapter/exec/pipeline.py +419 -0
  201. agent_adapter/exec/plan.py +134 -0
  202. agent_adapter/exec/retry.py +108 -0
  203. agent_adapter/exec/tool_loop.py +336 -0
  204. agent_adapter/flow/__init__.py +41 -0
  205. agent_adapter/flow/_cache.py +361 -0
  206. agent_adapter/flow/_digest.py +100 -0
  207. agent_adapter/flow/_drive.py +143 -0
  208. agent_adapter/flow/_durable.py +313 -0
  209. agent_adapter/flow/_gates.py +188 -0
  210. agent_adapter/flow/_invoke.py +51 -0
  211. agent_adapter/flow/_loop.py +181 -0
  212. agent_adapter/flow/_map.py +199 -0
  213. agent_adapter/flow/_nested.py +56 -0
  214. agent_adapter/flow/_nodes.py +425 -0
  215. agent_adapter/flow/_pause.py +202 -0
  216. agent_adapter/flow/_recover.py +171 -0
  217. agent_adapter/flow/_result.py +114 -0
  218. agent_adapter/flow/_resume.py +196 -0
  219. agent_adapter/flow/_seal.py +293 -0
  220. agent_adapter/flow/_step.py +160 -0
  221. agent_adapter/flow/_subcheck.py +235 -0
  222. agent_adapter/flow/_subflow.py +161 -0
  223. agent_adapter/flow/_trace.py +49 -0
  224. agent_adapter/flow/_updates.py +16 -0
  225. agent_adapter/flow/_withdraw.py +83 -0
  226. agent_adapter/flow/actions.py +107 -0
  227. agent_adapter/flow/diagram.py +226 -0
  228. agent_adapter/flow/graph.py +340 -0
  229. agent_adapter/flow/runner.py +383 -0
  230. agent_adapter/flow/spec.py +187 -0
  231. agent_adapter/flow/state.py +181 -0
  232. agent_adapter/flow/visit.py +75 -0
  233. agent_adapter/handlers/__init__.py +16 -0
  234. agent_adapter/handlers/consume.py +127 -0
  235. agent_adapter/handlers/envelope.py +100 -0
  236. agent_adapter/handlers/serverless.py +165 -0
  237. agent_adapter/hooks/__init__.py +53 -0
  238. agent_adapter/hooks/base.py +114 -0
  239. agent_adapter/hooks/builtin/__init__.py +21 -0
  240. agent_adapter/hooks/builtin/_content.py +106 -0
  241. agent_adapter/hooks/builtin/budget.py +410 -0
  242. agent_adapter/hooks/builtin/budgets/__init__.py +29 -0
  243. agent_adapter/hooks/builtin/budgets/_holds.py +58 -0
  244. agent_adapter/hooks/builtin/budgets/_keys.py +69 -0
  245. agent_adapter/hooks/builtin/budgets/_pricing.py +94 -0
  246. agent_adapter/hooks/builtin/budgets/_settings.py +56 -0
  247. agent_adapter/hooks/builtin/budgets/redis_store.py +221 -0
  248. agent_adapter/hooks/builtin/budgets/sqlalchemy_store.py +301 -0
  249. agent_adapter/hooks/builtin/budgets/sqlite_store.py +265 -0
  250. agent_adapter/hooks/builtin/budgets/status.py +41 -0
  251. agent_adapter/hooks/builtin/budgets/store.py +225 -0
  252. agent_adapter/hooks/builtin/guardrail.py +80 -0
  253. agent_adapter/hooks/builtin/guards/__init__.py +41 -0
  254. agent_adapter/hooks/builtin/guards/_walk.py +191 -0
  255. agent_adapter/hooks/builtin/guards/base.py +229 -0
  256. agent_adapter/hooks/builtin/guards/callable.py +61 -0
  257. agent_adapter/hooks/builtin/guards/nemo.py +59 -0
  258. agent_adapter/hooks/builtin/guards/pii.py +240 -0
  259. agent_adapter/hooks/builtin/guards/presidio.py +77 -0
  260. agent_adapter/hooks/builtin/logging.py +266 -0
  261. agent_adapter/hooks/builtin/rate_limit.py +105 -0
  262. agent_adapter/hooks/dispatch.py +111 -0
  263. agent_adapter/integrations/__init__.py +1 -0
  264. agent_adapter/integrations/_attach.py +175 -0
  265. agent_adapter/integrations/_compress_hooks.py +158 -0
  266. agent_adapter/integrations/_compress_parts.py +109 -0
  267. agent_adapter/integrations/_default_runner.py +63 -0
  268. agent_adapter/integrations/_durable_engine.py +71 -0
  269. agent_adapter/integrations/_durable_flows.py +404 -0
  270. agent_adapter/integrations/_durable_slice.py +42 -0
  271. agent_adapter/integrations/_expiring.py +93 -0
  272. agent_adapter/integrations/_native_approval.py +66 -0
  273. agent_adapter/integrations/_native_gate.py +373 -0
  274. agent_adapter/integrations/a2a/__init__.py +61 -0
  275. agent_adapter/integrations/a2a/_guard.py +198 -0
  276. agent_adapter/integrations/a2a/_owned.py +126 -0
  277. agent_adapter/integrations/a2a/_pending.py +76 -0
  278. agent_adapter/integrations/a2a/_pinned.py +156 -0
  279. agent_adapter/integrations/a2a/_task_store.py +127 -0
  280. agent_adapter/integrations/a2a/_wire.py +146 -0
  281. agent_adapter/integrations/a2a/agent.py +363 -0
  282. agent_adapter/integrations/a2a/card.py +98 -0
  283. agent_adapter/integrations/a2a/client.py +408 -0
  284. agent_adapter/integrations/a2a/server.py +377 -0
  285. agent_adapter/integrations/adk/__init__.py +25 -0
  286. agent_adapter/integrations/adk/_driver.py +317 -0
  287. agent_adapter/integrations/adk/_run.py +200 -0
  288. agent_adapter/integrations/adk/_steps.py +380 -0
  289. agent_adapter/integrations/adk/_support.py +98 -0
  290. agent_adapter/integrations/adk/_tokens.py +215 -0
  291. agent_adapter/integrations/adk/_workflow.py +179 -0
  292. agent_adapter/integrations/adk/compile.py +97 -0
  293. agent_adapter/integrations/adk/tools.py +221 -0
  294. agent_adapter/integrations/ag2.py +256 -0
  295. agent_adapter/integrations/ag2_compress.py +218 -0
  296. agent_adapter/integrations/ag_ui/__init__.py +25 -0
  297. agent_adapter/integrations/ag_ui/_channel.py +69 -0
  298. agent_adapter/integrations/ag_ui/_events.py +159 -0
  299. agent_adapter/integrations/ag_ui/_input.py +130 -0
  300. agent_adapter/integrations/ag_ui/_interrupts.py +124 -0
  301. agent_adapter/integrations/ag_ui/_resume.py +153 -0
  302. agent_adapter/integrations/ag_ui/_support.py +64 -0
  303. agent_adapter/integrations/ag_ui/bridge.py +169 -0
  304. agent_adapter/integrations/ag_ui/run.py +88 -0
  305. agent_adapter/integrations/ag_ui/starlette.py +110 -0
  306. agent_adapter/integrations/agent_framework.py +302 -0
  307. agent_adapter/integrations/agno.py +160 -0
  308. agent_adapter/integrations/agno_compress.py +154 -0
  309. agent_adapter/integrations/anthropic.py +78 -0
  310. agent_adapter/integrations/autogen.py +155 -0
  311. agent_adapter/integrations/autogen_compress.py +188 -0
  312. agent_adapter/integrations/base.py +185 -0
  313. agent_adapter/integrations/camel.py +319 -0
  314. agent_adapter/integrations/claude_agent.py +372 -0
  315. agent_adapter/integrations/crewai.py +92 -0
  316. agent_adapter/integrations/dbos.py +255 -0
  317. agent_adapter/integrations/discovery.py +171 -0
  318. agent_adapter/integrations/dspy.py +112 -0
  319. agent_adapter/integrations/gemini.py +398 -0
  320. agent_adapter/integrations/haystack.py +320 -0
  321. agent_adapter/integrations/langchain.py +228 -0
  322. agent_adapter/integrations/langgraph/__init__.py +34 -0
  323. agent_adapter/integrations/langgraph/_channels.py +177 -0
  324. agent_adapter/integrations/langgraph/_context.py +39 -0
  325. agent_adapter/integrations/langgraph/_durable.py +163 -0
  326. agent_adapter/integrations/langgraph/_gate.py +141 -0
  327. agent_adapter/integrations/langgraph/_integration.py +44 -0
  328. agent_adapter/integrations/langgraph/_memo.py +70 -0
  329. agent_adapter/integrations/langgraph/_node.py +375 -0
  330. agent_adapter/integrations/langgraph/_run.py +358 -0
  331. agent_adapter/integrations/langgraph/_spent.py +212 -0
  332. agent_adapter/integrations/langgraph/_store_decisions.py +86 -0
  333. agent_adapter/integrations/langgraph/_user_node.py +137 -0
  334. agent_adapter/integrations/langgraph/approval.py +319 -0
  335. agent_adapter/integrations/langgraph/compile.py +139 -0
  336. agent_adapter/integrations/langgraph/compress.py +78 -0
  337. agent_adapter/integrations/langgraph/tools.py +346 -0
  338. agent_adapter/integrations/llamaindex.py +188 -0
  339. agent_adapter/integrations/mcp/__init__.py +91 -0
  340. agent_adapter/integrations/mcp/_approval.py +246 -0
  341. agent_adapter/integrations/mcp/_handlers.py +340 -0
  342. agent_adapter/integrations/mcp/_peer.py +67 -0
  343. agent_adapter/integrations/mcp/_resume.py +269 -0
  344. agent_adapter/integrations/mcp/_scope.py +230 -0
  345. agent_adapter/integrations/mcp/_task_params.py +45 -0
  346. agent_adapter/integrations/mcp/_task_service.py +381 -0
  347. agent_adapter/integrations/mcp/_task_store.py +196 -0
  348. agent_adapter/integrations/mcp/_task_table.py +232 -0
  349. agent_adapter/integrations/mcp/_tasks_client.py +180 -0
  350. agent_adapter/integrations/mcp/annotations.py +147 -0
  351. agent_adapter/integrations/mcp/client.py +357 -0
  352. agent_adapter/integrations/mcp/oauth.py +160 -0
  353. agent_adapter/integrations/mcp/server.py +338 -0
  354. agent_adapter/integrations/mcp/tasks.py +98 -0
  355. agent_adapter/integrations/openai.py +86 -0
  356. agent_adapter/integrations/openai_agents.py +366 -0
  357. agent_adapter/integrations/openapi/__init__.py +150 -0
  358. agent_adapter/integrations/openapi/_decode.py +128 -0
  359. agent_adapter/integrations/openapi/_document.py +130 -0
  360. agent_adapter/integrations/openapi/_http.py +318 -0
  361. agent_adapter/integrations/openapi/_names.py +30 -0
  362. agent_adapter/integrations/openapi/_redact.py +56 -0
  363. agent_adapter/integrations/openapi/_refs.py +264 -0
  364. agent_adapter/integrations/openapi/_report.py +72 -0
  365. agent_adapter/integrations/openapi/_schema.py +387 -0
  366. agent_adapter/integrations/openapi/auth.py +86 -0
  367. agent_adapter/integrations/pydantic_ai.py +293 -0
  368. agent_adapter/integrations/pydantic_ai_compress.py +245 -0
  369. agent_adapter/integrations/semantic_kernel.py +389 -0
  370. agent_adapter/integrations/smolagents.py +202 -0
  371. agent_adapter/integrations/smolagents_compress.py +132 -0
  372. agent_adapter/integrations/strands.py +229 -0
  373. agent_adapter/integrations/strands_compress.py +178 -0
  374. agent_adapter/integrations/temporal.py +351 -0
  375. agent_adapter/memory/__init__.py +35 -0
  376. agent_adapter/memory/_base.py +333 -0
  377. agent_adapter/memory/_clients.py +84 -0
  378. agent_adapter/memory/_sqlite_sql.py +224 -0
  379. agent_adapter/memory/callable.py +110 -0
  380. agent_adapter/memory/graphiti.py +131 -0
  381. agent_adapter/memory/mem0.py +171 -0
  382. agent_adapter/memory/port.py +47 -0
  383. agent_adapter/memory/records.py +240 -0
  384. agent_adapter/memory/sqlite.py +391 -0
  385. agent_adapter/memory/tools.py +165 -0
  386. agent_adapter/memory/zep.py +196 -0
  387. agent_adapter/models/__init__.py +56 -0
  388. agent_adapter/models/_anthropic_convert.py +252 -0
  389. agent_adapter/models/_anthropic_schema.py +84 -0
  390. agent_adapter/models/_convert.py +139 -0
  391. agent_adapter/models/_gemini_convert.py +265 -0
  392. agent_adapter/models/_llm_call.py +401 -0
  393. agent_adapter/models/_openai_chat.py +201 -0
  394. agent_adapter/models/_openai_common.py +33 -0
  395. agent_adapter/models/_openai_responses.py +239 -0
  396. agent_adapter/models/_port.py +394 -0
  397. agent_adapter/models/anthropic.py +176 -0
  398. agent_adapter/models/callable.py +199 -0
  399. agent_adapter/models/entries.py +42 -0
  400. agent_adapter/models/errors.py +190 -0
  401. agent_adapter/models/fallback.py +150 -0
  402. agent_adapter/models/gemini.py +184 -0
  403. agent_adapter/models/instrument.py +257 -0
  404. agent_adapter/models/openai.py +210 -0
  405. agent_adapter/models/usage.py +130 -0
  406. agent_adapter/optimiser/__init__.py +55 -0
  407. agent_adapter/optimiser/__main__.py +192 -0
  408. agent_adapter/optimiser/_budget.py +126 -0
  409. agent_adapter/optimiser/_fatal.py +119 -0
  410. agent_adapter/optimiser/_files.py +29 -0
  411. agent_adapter/optimiser/_hook_surface.py +90 -0
  412. agent_adapter/optimiser/_outcome.py +99 -0
  413. agent_adapter/optimiser/_reflection.py +89 -0
  414. agent_adapter/optimiser/_schema_check.py +3 -0
  415. agent_adapter/optimiser/_select.py +172 -0
  416. agent_adapter/optimiser/_stages.py +180 -0
  417. agent_adapter/optimiser/_state.py +153 -0
  418. agent_adapter/optimiser/_transcript.py +191 -0
  419. agent_adapter/optimiser/apply.py +73 -0
  420. agent_adapter/optimiser/callable_host.py +194 -0
  421. agent_adapter/optimiser/cases.py +3 -0
  422. agent_adapter/optimiser/compose.py +348 -0
  423. agent_adapter/optimiser/evidence.py +117 -0
  424. agent_adapter/optimiser/graders.py +26 -0
  425. agent_adapter/optimiser/hosts.py +352 -0
  426. agent_adapter/optimiser/lessons.py +215 -0
  427. agent_adapter/optimiser/loop.py +362 -0
  428. agent_adapter/optimiser/model.py +265 -0
  429. agent_adapter/optimiser/probe.py +245 -0
  430. agent_adapter/optimiser/prompts.py +256 -0
  431. agent_adapter/optimiser/propose.py +164 -0
  432. agent_adapter/optimiser/report.py +217 -0
  433. agent_adapter/optimiser/surface.py +172 -0
  434. agent_adapter/policy/__init__.py +95 -0
  435. agent_adapter/policy/_build.py +146 -0
  436. agent_adapter/policy/_hooks.py +143 -0
  437. agent_adapter/policy/_load.py +249 -0
  438. agent_adapter/policy/_scope.py +76 -0
  439. agent_adapter/policy/condition.py +229 -0
  440. agent_adapter/policy/errors.py +26 -0
  441. agent_adapter/policy/explain.py +89 -0
  442. agent_adapter/policy/model.py +198 -0
  443. agent_adapter/policy/policy.py +303 -0
  444. agent_adapter/py.typed +0 -0
  445. agent_adapter/retrieval/__init__.py +34 -0
  446. agent_adapter/retrieval/_base.py +171 -0
  447. agent_adapter/retrieval/callable.py +63 -0
  448. agent_adapter/retrieval/documents.py +171 -0
  449. agent_adapter/retrieval/embedding.py +158 -0
  450. agent_adapter/retrieval/langchain.py +79 -0
  451. agent_adapter/retrieval/llamaindex.py +107 -0
  452. agent_adapter/retrieval/port.py +22 -0
  453. agent_adapter/retrieval/tool.py +120 -0
  454. agent_adapter/runtime/__init__.py +9 -0
  455. agent_adapter/runtime/_fork.py +46 -0
  456. agent_adapter/runtime/current.py +38 -0
  457. agent_adapter/runtime/ids.py +25 -0
  458. agent_adapter/runtime/loop_local.py +131 -0
  459. agent_adapter/runtime/loop_runner.py +303 -0
  460. agent_adapter/runtime/sync.py +102 -0
  461. agent_adapter/sandbox/__init__.py +35 -0
  462. agent_adapter/sandbox/_base.py +293 -0
  463. agent_adapter/sandbox/_bootstrap.py +238 -0
  464. agent_adapter/sandbox/_checks.py +190 -0
  465. agent_adapter/sandbox/_process.py +112 -0
  466. agent_adapter/sandbox/_protocol.py +97 -0
  467. agent_adapter/sandbox/callable.py +98 -0
  468. agent_adapter/sandbox/docker.py +232 -0
  469. agent_adapter/sandbox/local.py +124 -0
  470. agent_adapter/sandbox/port.py +84 -0
  471. agent_adapter/sandbox/tool.py +198 -0
  472. agent_adapter/schema/__init__.py +1 -0
  473. agent_adapter/schema/_names.py +30 -0
  474. agent_adapter/schema/models.py +125 -0
  475. agent_adapter/schema/portable.py +99 -0
  476. agent_adapter/schema/transforms.py +165 -0
  477. agent_adapter/server/__init__.py +56 -0
  478. agent_adapter/server/__main__.py +141 -0
  479. agent_adapter/server/_approval.py +68 -0
  480. agent_adapter/server/_budget.py +56 -0
  481. agent_adapter/server/_calls.py +363 -0
  482. agent_adapter/server/_health.py +54 -0
  483. agent_adapter/server/_hosts.py +131 -0
  484. agent_adapter/server/_idempotency.py +174 -0
  485. agent_adapter/server/_openapi30.py +333 -0
  486. agent_adapter/server/_payloads.py +186 -0
  487. agent_adapter/server/_reads.py +123 -0
  488. agent_adapter/server/_runs.py +81 -0
  489. agent_adapter/server/_sse.py +147 -0
  490. agent_adapter/server/_state.py +164 -0
  491. agent_adapter/server/asgi.py +361 -0
  492. agent_adapter/server/auth.py +178 -0
  493. agent_adapter/server/events.py +120 -0
  494. agent_adapter/server/idempotency.py +248 -0
  495. agent_adapter/server/openapi.py +371 -0
  496. agent_adapter/server/problems.py +93 -0
  497. agent_adapter/server/service.py +380 -0
  498. agent_adapter/server/wsgi.py +330 -0
  499. agent_adapter/tracing/__init__.py +26 -0
  500. agent_adapter/tracing/_content.py +87 -0
  501. agent_adapter/tracing/_genai.py +255 -0
  502. agent_adapter/tracing/events.py +252 -0
  503. agent_adapter/tracing/otel.py +358 -0
  504. agent_adapter/tracing/semconv.py +84 -0
  505. agent_adapter/tracing/sinks.py +184 -0
  506. agent_adapter/viewer/__init__.py +35 -0
  507. agent_adapter/viewer/_case_routes.py +133 -0
  508. agent_adapter/viewer/_drain.py +26 -0
  509. agent_adapter/viewer/_evals.py +244 -0
  510. agent_adapter/viewer/_files.py +158 -0
  511. agent_adapter/viewer/_fold.py +166 -0
  512. agent_adapter/viewer/_otlp_import.py +162 -0
  513. agent_adapter/viewer/_otlp_spans.py +184 -0
  514. agent_adapter/viewer/_runs_routes.py +154 -0
  515. agent_adapter/viewer/_scrub.py +118 -0
  516. agent_adapter/viewer/_search.py +112 -0
  517. agent_adapter/viewer/_segments.py +177 -0
  518. agent_adapter/viewer/_tags.py +163 -0
  519. agent_adapter/viewer/approvals.py +112 -0
  520. agent_adapter/viewer/assets.py +159 -0
  521. agent_adapter/viewer/chat/__init__.py +19 -0
  522. agent_adapter/viewer/chat/agent_task.py +30 -0
  523. agent_adapter/viewer/chat/approval_history.py +83 -0
  524. agent_adapter/viewer/chat/approvals.py +242 -0
  525. agent_adapter/viewer/chat/builtin.py +174 -0
  526. agent_adapter/viewer/chat/contract.py +7 -0
  527. agent_adapter/viewer/chat/evalcases.py +161 -0
  528. agent_adapter/viewer/chat/files.py +151 -0
  529. agent_adapter/viewer/chat/host.py +388 -0
  530. agent_adapter/viewer/chat/invoke.py +60 -0
  531. agent_adapter/viewer/chat/live.py +208 -0
  532. agent_adapter/viewer/chat/memory.py +215 -0
  533. agent_adapter/viewer/chat/memory_routes.py +60 -0
  534. agent_adapter/viewer/chat/memory_turns.py +82 -0
  535. agent_adapter/viewer/chat/records.py +162 -0
  536. agent_adapter/viewer/chat/routes.py +299 -0
  537. agent_adapter/viewer/chat/sessions.py +231 -0
  538. agent_adapter/viewer/chat/settle.py +112 -0
  539. agent_adapter/viewer/chat/setup.py +199 -0
  540. agent_adapter/viewer/chat/stream.py +57 -0
  541. agent_adapter/viewer/chat/targets.py +40 -0
  542. agent_adapter/viewer/chat/turn_io.py +111 -0
  543. agent_adapter/viewer/chat/watch.py +102 -0
  544. agent_adapter/viewer/export.py +47 -0
  545. agent_adapter/viewer/lanes.py +205 -0
  546. agent_adapter/viewer/launch.py +74 -0
  547. agent_adapter/viewer/layout.py +236 -0
  548. agent_adapter/viewer/recorder.py +339 -0
  549. agent_adapter/viewer/runs.py +256 -0
  550. agent_adapter/viewer/server.py +425 -0
  551. agent_adapter/viewer/serving.py +199 -0
  552. agent_adapter/viewer/static/app.js +339 -0
  553. agent_adapter/viewer/static/chat.css +152 -0
  554. agent_adapter/viewer/static/chat.js +370 -0
  555. agent_adapter/viewer/static/chatapi.js +229 -0
  556. agent_adapter/viewer/static/chatcards.js +321 -0
  557. agent_adapter/viewer/static/chatcomposer.js +150 -0
  558. agent_adapter/viewer/static/chatdemo.js +323 -0
  559. agent_adapter/viewer/static/chatextras.js +271 -0
  560. agent_adapter/viewer/static/chatmemory.js +107 -0
  561. agent_adapter/viewer/static/chatsessions.js +57 -0
  562. agent_adapter/viewer/static/compare.js +254 -0
  563. agent_adapter/viewer/static/data.js +213 -0
  564. agent_adapter/viewer/static/evals.css +29 -0
  565. agent_adapter/viewer/static/evals.js +113 -0
  566. agent_adapter/viewer/static/evalscards.js +136 -0
  567. agent_adapter/viewer/static/evalsview.js +233 -0
  568. agent_adapter/viewer/static/events.js +160 -0
  569. agent_adapter/viewer/static/favicon.svg +1 -0
  570. agent_adapter/viewer/static/graph.css +109 -0
  571. agent_adapter/viewer/static/graph.js +271 -0
  572. agent_adapter/viewer/static/graphbar.js +315 -0
  573. agent_adapter/viewer/static/graphlive.js +263 -0
  574. agent_adapter/viewer/static/graphnav.js +237 -0
  575. agent_adapter/viewer/static/index.html +138 -0
  576. agent_adapter/viewer/static/inspector.js +245 -0
  577. agent_adapter/viewer/static/markdown.js +356 -0
  578. agent_adapter/viewer/static/panels.js +227 -0
  579. agent_adapter/viewer/static/runcases.js +116 -0
  580. agent_adapter/viewer/static/runsearch.js +112 -0
  581. agent_adapter/viewer/static/statepanel.js +154 -0
  582. agent_adapter/viewer/static/tabs.css +37 -0
  583. agent_adapter/viewer/static/timeline.js +99 -0
  584. agent_adapter/viewer/static/viewer.css +159 -0
  585. agent_adapter/viewer/static/views.js +89 -0
  586. agent_adapter-1.1.0.dist-info/METADATA +285 -0
  587. agent_adapter-1.1.0.dist-info/RECORD +591 -0
  588. agent_adapter-1.1.0.dist-info/WHEEL +4 -0
  589. agent_adapter-1.1.0.dist-info/entry_points.txt +29 -0
  590. agent_adapter-1.1.0.dist-info/licenses/LICENSE +202 -0
  591. agent_adapter-1.1.0.dist-info/licenses/NOTICE +4 -0
@@ -0,0 +1,375 @@
1
+ """Agent Adapter: framework-independent tools, parallel execution and flows for LLM agents.
2
+
3
+ Names load on first use (PEP 562), so `import agent_adapter` stays cheap. Every other
4
+ public name lives in its home subpackage: errors in `agent_adapter.errors`, the rest in
5
+ `agent_adapter.exec`, `.approval`, `.hooks`, `.cost`, `.cache`, `.flow` and so on.
6
+ """
7
+
8
+ from agent_adapter._version import __version__
9
+
10
+ # Not `typing.TYPE_CHECKING`: importing typing would triple the import cost. Type checkers
11
+ # treat any constant named TYPE_CHECKING as true.
12
+ TYPE_CHECKING = False
13
+
14
+ if TYPE_CHECKING:
15
+ from pathlib import Path
16
+ from typing import Any
17
+
18
+ from agent_adapter.approval.builtin import AutoApprove, AutoDeny, CallbackApproval
19
+ from agent_adapter.approval.deferred import DeferredApproval
20
+ from agent_adapter.approval.redis_store import RedisApprovalStore
21
+ from agent_adapter.approval.sqlite_store import SQLiteApprovalStore
22
+ from agent_adapter.approval.store import MemoryApprovalStore
23
+ from agent_adapter.cache.memory import MemoryCache
24
+ from agent_adapter.core._default import default_registry, tool, wrap
25
+ from agent_adapter.core.context import ToolContext
26
+ from agent_adapter.core.errors import (
27
+ AdapterError,
28
+ ApprovalDenied,
29
+ ApprovalPending,
30
+ MissingDependency,
31
+ ToolError,
32
+ )
33
+ from agent_adapter.core.imported import spec_from_schema
34
+ from agent_adapter.core.messages import LLMRequest, LLMResponse, Message, ToolDef
35
+ from agent_adapter.core.registry import Registry
36
+ from agent_adapter.core.tool import ToolSpec, build_spec
37
+ from agent_adapter.core.types import (
38
+ ApprovalDecision,
39
+ ApprovalRequest,
40
+ Decision,
41
+ Event,
42
+ LedgerEntry,
43
+ ToolCall,
44
+ ToolResult,
45
+ Usage,
46
+ )
47
+ from agent_adapter.cost.ledger import Ledger
48
+ from agent_adapter.cost.prices import Prices
49
+ from agent_adapter.exec.defaults import acall, call, configure, set_default_executor
50
+ from agent_adapter.exec.executor import Executor
51
+ from agent_adapter.exec.guards import RunLimits
52
+ from agent_adapter.exec.plan import Step
53
+ from agent_adapter.exec.tool_loop import run_tool_loop
54
+ from agent_adapter.flow.runner import FlowRunner
55
+ from agent_adapter.flow.spec import Flow
56
+ from agent_adapter.hooks.base import Hook
57
+ from agent_adapter.hooks.builtin.budget import BudgetHook
58
+ from agent_adapter.hooks.builtin.guardrail import GuardrailHook
59
+ from agent_adapter.hooks.builtin.logging import LoggingHook
60
+ from agent_adapter.hooks.builtin.rate_limit import RateLimitHook
61
+ from agent_adapter.integrations._attach import attach
62
+ from agent_adapter.models.callable import CallableModel
63
+ from agent_adapter.models.fallback import FallbackModel
64
+ from agent_adapter.runtime.sync import run_sync
65
+
66
+ # name -> module that defines it; kept in step with the TYPE_CHECKING block by tests.
67
+ _LAZY: dict[str, str] = {
68
+ # Tools
69
+ "Registry": "agent_adapter.core.registry",
70
+ "ToolSpec": "agent_adapter.core.tool",
71
+ "build_spec": "agent_adapter.core.tool",
72
+ "spec_from_schema": "agent_adapter.core.imported",
73
+ "ToolContext": "agent_adapter.core.context",
74
+ "ToolCall": "agent_adapter.core.types",
75
+ "ToolResult": "agent_adapter.core.types",
76
+ "Usage": "agent_adapter.core.types",
77
+ # Running
78
+ "Executor": "agent_adapter.exec.executor",
79
+ "RunLimits": "agent_adapter.exec.guards",
80
+ "Step": "agent_adapter.exec.plan",
81
+ "run_tool_loop": "agent_adapter.exec.tool_loop",
82
+ "run_sync": "agent_adapter.runtime.sync",
83
+ "set_default_executor": "agent_adapter.exec.defaults",
84
+ "configure": "agent_adapter.exec.defaults",
85
+ "call": "agent_adapter.exec.defaults",
86
+ "acall": "agent_adapter.exec.defaults",
87
+ "attach": "agent_adapter.integrations._attach",
88
+ # Approval
89
+ "AutoApprove": "agent_adapter.approval.builtin",
90
+ "AutoDeny": "agent_adapter.approval.builtin",
91
+ "CallbackApproval": "agent_adapter.approval.builtin",
92
+ "DeferredApproval": "agent_adapter.approval.deferred",
93
+ "ApprovalRequest": "agent_adapter.core.types",
94
+ "ApprovalDecision": "agent_adapter.core.types",
95
+ "Decision": "agent_adapter.core.types",
96
+ "MemoryApprovalStore": "agent_adapter.approval.store",
97
+ "SQLiteApprovalStore": "agent_adapter.approval.sqlite_store",
98
+ "RedisApprovalStore": "agent_adapter.approval.redis_store",
99
+ # Hooks, cost, cache
100
+ "Hook": "agent_adapter.hooks.base",
101
+ "LoggingHook": "agent_adapter.hooks.builtin.logging",
102
+ "GuardrailHook": "agent_adapter.hooks.builtin.guardrail",
103
+ "BudgetHook": "agent_adapter.hooks.builtin.budget",
104
+ "RateLimitHook": "agent_adapter.hooks.builtin.rate_limit",
105
+ "Ledger": "agent_adapter.cost.ledger",
106
+ "LedgerEntry": "agent_adapter.core.types",
107
+ "Prices": "agent_adapter.cost.prices",
108
+ "MemoryCache": "agent_adapter.cache.memory",
109
+ # Flows
110
+ "Flow": "agent_adapter.flow.spec",
111
+ "FlowRunner": "agent_adapter.flow.runner",
112
+ # Model messages
113
+ "LLMRequest": "agent_adapter.core.messages",
114
+ "LLMResponse": "agent_adapter.core.messages",
115
+ "Message": "agent_adapter.core.messages",
116
+ "ToolDef": "agent_adapter.core.messages",
117
+ "Event": "agent_adapter.core.types",
118
+ # Model ports that need no extra
119
+ "CallableModel": "agent_adapter.models.callable",
120
+ "FallbackModel": "agent_adapter.models.fallback",
121
+ # Errors (the five most caught; the rest are in agent_adapter.errors)
122
+ "AdapterError": "agent_adapter.core.errors",
123
+ "ToolError": "agent_adapter.core.errors",
124
+ "ApprovalDenied": "agent_adapter.core.errors",
125
+ "ApprovalPending": "agent_adapter.core.errors",
126
+ "MissingDependency": "agent_adapter.core.errors",
127
+ # The default registry, created on first access
128
+ "default_registry": "agent_adapter.core._default",
129
+ "tool": "agent_adapter.core._default",
130
+ "wrap": "agent_adapter.core._default",
131
+ }
132
+
133
+ # Names that left the top level in 1.0 -> their public home.
134
+ _MOVED: dict[str, str] = {
135
+ **dict.fromkeys(
136
+ (
137
+ "ApprovalAlreadyDecided",
138
+ "ApprovalNotFound",
139
+ "AuthError",
140
+ "BudgetExceeded",
141
+ "ConfigError",
142
+ "DuplicateTool",
143
+ "ErrorInfo",
144
+ "FlowCompileError",
145
+ "FlowDefinitionError",
146
+ "FlowError",
147
+ "FlowLoopExceeded",
148
+ "Forbidden",
149
+ "GuardrailBlocked",
150
+ "IntegrationError",
151
+ "ModelAuthError",
152
+ "ModelBadRequest",
153
+ "ModelContentFiltered",
154
+ "ModelContextOverflow",
155
+ "ModelError",
156
+ "ModelOutputInvalid",
157
+ "ModelRateLimited",
158
+ "ModelTimeout",
159
+ "ModelUnavailable",
160
+ "OptimiserError",
161
+ "PlanInvalid",
162
+ "RunLimitExceeded",
163
+ "SchemaNotPortable",
164
+ "ToolArgsInvalid",
165
+ "ToolDefinitionError",
166
+ "ToolFailed",
167
+ "ToolNotFound",
168
+ "ToolTimeout",
169
+ "ToolUsageError",
170
+ "Unauthorized",
171
+ ),
172
+ "agent_adapter.errors",
173
+ ),
174
+ "ShortCircuit": "agent_adapter.hooks",
175
+ }
176
+
177
+ # Subpackages reachable as attributes after a bare `import agent_adapter`.
178
+ _SUBPACKAGES = frozenset(
179
+ {
180
+ "approval",
181
+ "audit",
182
+ "cache",
183
+ "chat",
184
+ "cli",
185
+ "context",
186
+ "core",
187
+ "cost",
188
+ "embeddings",
189
+ "evals",
190
+ "handlers",
191
+ "errors",
192
+ "exec",
193
+ "flow",
194
+ "hooks",
195
+ "integrations",
196
+ "memory",
197
+ "models",
198
+ "optimiser",
199
+ "policy",
200
+ "retrieval",
201
+ "runtime",
202
+ "sandbox",
203
+ "schema",
204
+ "server",
205
+ "tracing",
206
+ "viewer",
207
+ }
208
+ )
209
+
210
+
211
+ def _getattr(name: str) -> "Any":
212
+ """Load a public name or a subpackage on first access; explain names that moved."""
213
+ import importlib
214
+
215
+ if name in _LAZY:
216
+ value = getattr(importlib.import_module(_LAZY[name]), name)
217
+ elif name in _SUBPACKAGES:
218
+ value = importlib.import_module(f"{__name__}.{name}")
219
+ elif name in _MOVED:
220
+ message = f"{name} moved: from {_MOVED[name]} import {name}"
221
+ if _in_from_import(): # `from x import y` would replace an AttributeError's text
222
+ raise ImportError(message, name=__name__)
223
+ raise AttributeError(message, name=name)
224
+ else:
225
+ hint = _hint(name)
226
+ if hint and _in_from_import():
227
+ raise ImportError(f"cannot import name {name!r} from {__name__!r}; {hint}", name=name)
228
+ raise AttributeError(
229
+ f"module {__name__!r} has no attribute {name!r}; "
230
+ + (hint or "see agent_adapter.__all__ for the top-level names"),
231
+ name=name,
232
+ )
233
+ globals()[name] = value # later lookups skip __getattr__
234
+ return value
235
+
236
+
237
+ def _hint(name: str) -> str:
238
+ """Where a missing name lives, or the close top-level name; "" when nothing fits."""
239
+ if name.startswith("_"):
240
+ return "" # dunder probes (copy, pickle, IDEs) stay cheap
241
+ homes = _homes().get(name)
242
+ if homes:
243
+ return f"it lives in {', '.join(homes)}: from {homes[0]} import {name}"
244
+ import difflib
245
+
246
+ close = difflib.get_close_matches(name, [*__all__, *_MOVED], n=1, cutoff=0.8)
247
+ if close:
248
+ return f"did you mean {close[0]!r}? see agent_adapter.__all__ for the top-level names"
249
+ return ""
250
+
251
+
252
+ _HOMES: "dict[str, list[str]] | None" = None
253
+
254
+
255
+ def _homes() -> "dict[str, list[str]]":
256
+ """Name -> public modules that export it, read from the package source (no imports)."""
257
+ global _HOMES
258
+ if _HOMES is None:
259
+ from pathlib import Path
260
+
261
+ root = Path(__file__).parent
262
+ files = [*root.glob("*/__init__.py"), *root.glob("integrations/*/__init__.py")]
263
+ files += [p for p in root.glob("integrations/*.py") if not p.name.startswith("_")]
264
+ homes: dict[str, list[str]] = {}
265
+ for path in sorted(files):
266
+ parts = path.relative_to(root.parent).with_suffix("").parts
267
+ module = ".".join(parts[:-1] if parts[-1] == "__init__" else parts)
268
+ for exported in _exports(path):
269
+ if exported not in _LAZY:
270
+ homes.setdefault(exported, []).append(module)
271
+ _HOMES = homes
272
+ return _HOMES
273
+
274
+
275
+ def _exports(path: "Path") -> "tuple[str, ...]":
276
+ """The literal `__all__` of a source file; () when unreadable or not a literal."""
277
+ import ast
278
+
279
+ try:
280
+ tree = ast.parse(path.read_text(encoding="utf-8"))
281
+ except (OSError, SyntaxError, UnicodeDecodeError):
282
+ return ()
283
+ for node in tree.body:
284
+ if isinstance(node, ast.Assign) and any(
285
+ isinstance(target, ast.Name) and target.id == "__all__" for target in node.targets
286
+ ):
287
+ try:
288
+ names = ast.literal_eval(node.value)
289
+ except ValueError:
290
+ return ()
291
+ return tuple(n for n in names if isinstance(n, str))
292
+ return ()
293
+
294
+
295
+ def _in_from_import() -> bool:
296
+ """True when the code that triggered `__getattr__` runs `from agent_adapter import ...`."""
297
+ import opcode
298
+ import sys
299
+
300
+ try:
301
+ frame = sys._getframe(3) # 0: here, 1: _getattr, 2: __getattr__, 3: the importer
302
+ return frame.f_code.co_code[frame.f_lasti] == opcode.opmap["IMPORT_FROM"]
303
+ except (AttributeError, IndexError, KeyError, ValueError):
304
+ return False # no CPython frames: the AttributeError message still applies
305
+
306
+
307
+ if not TYPE_CHECKING: # hidden from type checkers, so an unknown name stays a type error
308
+
309
+ def __getattr__(name: str) -> "Any":
310
+ """PEP 562 hook: see `_getattr`."""
311
+ return _getattr(name)
312
+
313
+
314
+ def __dir__() -> list[str]:
315
+ """The public names plus any subpackage already loaded."""
316
+ return sorted({*__all__, *(name for name in globals() if name in _SUBPACKAGES)})
317
+
318
+
319
+ __all__ = [
320
+ "AdapterError",
321
+ "ApprovalDecision",
322
+ "ApprovalDenied",
323
+ "ApprovalPending",
324
+ "ApprovalRequest",
325
+ "AutoApprove",
326
+ "AutoDeny",
327
+ "BudgetHook",
328
+ "CallableModel",
329
+ "CallbackApproval",
330
+ "Decision",
331
+ "DeferredApproval",
332
+ "Event",
333
+ "Executor",
334
+ "FallbackModel",
335
+ "Flow",
336
+ "FlowRunner",
337
+ "GuardrailHook",
338
+ "Hook",
339
+ "LLMRequest",
340
+ "LLMResponse",
341
+ "Ledger",
342
+ "LedgerEntry",
343
+ "LoggingHook",
344
+ "MemoryApprovalStore",
345
+ "MemoryCache",
346
+ "Message",
347
+ "MissingDependency",
348
+ "Prices",
349
+ "RateLimitHook",
350
+ "RedisApprovalStore",
351
+ "Registry",
352
+ "RunLimits",
353
+ "SQLiteApprovalStore",
354
+ "Step",
355
+ "ToolCall",
356
+ "ToolContext",
357
+ "ToolDef",
358
+ "ToolError",
359
+ "ToolResult",
360
+ "ToolSpec",
361
+ "Usage",
362
+ "__version__",
363
+ "acall",
364
+ "attach",
365
+ "build_spec",
366
+ "call",
367
+ "configure",
368
+ "default_registry",
369
+ "run_sync",
370
+ "run_tool_loop",
371
+ "set_default_executor",
372
+ "spec_from_schema",
373
+ "tool",
374
+ "wrap",
375
+ ]
@@ -0,0 +1,5 @@
1
+ """`python -m agent_adapter`: the same as the `agent-adapter` command."""
2
+
3
+ from agent_adapter.cli.main import main
4
+
5
+ raise SystemExit(main())