k9aif/k9-aif-framework: K9-AIF 1.35.0
Year: 2026
Type: software
Abstract: K9-AIF 1.35.0 on PyPI: pip install k9-aif==1.35.0. It also contains 1.33.0 and 1.34.0, which were not published on their own (PyPI goes from 1.32.0 to 1.35.0). Highlights OpenAI Agents SDK: your own agent guardrails under K9-AIF. input_guardrails / output_guardrails in agent YAML run beside K9's checks; a tripwire becomes a block (PermissionError) or a K9X HIL review (RequiresHIL). current_run_config() routes a guardrail's own model call through the K9 Model Router. An SDK coverage table documents every SDK feature. Conditions read inside structured output. A squad's when: and a rule can test churn.output.is_churn_risk; before, they stopped at the JSON text and never matched. Squads can mix OpenAI agents with K9RulesAgent, and a rules step resumes with the person's decision instead of asking again. 1.34.0: Granite Guardian screens every string in the payload, all of it, in chunks (before: the first 4000 characters of one key). 1.33.0: OpenAI's Manager pattern (agent_tools:). Full details below, from CHANGELOG.md. [1.35.0] — 2026-11-22 Fixed A condition on structured output never held. K9OpenAIAgent passes a structured result on as JSON text ({"output": "{\"is_churn_risk\": true}"}). A squad's when: {key: churn.output.is_churn_risk, ...} and a K9RulesAgent rule when: "churn.output.is_churn_risk == true" walked dictionaries only, stopped at the text and found nothing: the rule never matched (a churn risk was allowed) and the when: never held. Found 2026-11-22 while writing OpenAI's own guardrail example (the churn check, A practical guide to building agents, pp. 28-29) as a K9-AIF squad. Applications had worked around it in code (the AP demo's APRulesAgent parses the invoice step's output itself). Now BaseSquad's when: and K9RulesAdapter's conditions read inside JSON text holding an object or list (and index lists: items.0.amount), and BaseRulesAdapter.execute() hands every rules engine (K9RulesAdapter, RestRulesAdapter, GoRulesAdapter, your own) the step outputs parsed, so a decision service receives fields, not text. The stored step results stay JSON text: what the next agent reads is unchanged. A squad could not mix OpenAI agents with a K9RulesAgent. SquadLoader passed every agent all of agent_kwargs; the rules agent rejected capabilities / model_provider with TypeError, so applications needed a subclass that swallowed them. Now each agent gets only the keywords its constructor takes (a constructor with **kwargs still gets all). A rules step asked the same question again after the person answered. When K9RulesAgent raised RequiresHIL (then: hil) and the decision came back, the resumed squad re-ran the step, the rule matched again and the same case was raised again. Now the step marks its resume_state and, on the resume, returns the person's decision (decision: approved | rejected, decided_by, comment) for the next step's when:. Added The OpenAI Agents SDK's own agent guardrails (k9_adapters/openai_agents/openai_guardrails.py), in both K9OpenAIAgent and OpenAIAgentsOrchestratorAdapter. Agent YAML lists them by function + module (input_guardrails:, output_guardrails:; a decorated guardrail or a plain function). The SDK runs them as it always does, beside K9's own checks. A tripwire becomes PermissionError (on_trip: block, default, the same signal as a k9x Shield block) or, for input guardrails, RequiresHIL (on_trip: hil, hil_queue): approved, the run starts again without that guardrail; rejected, PermissionError. Refused at construction: an input guardrail the SDK would never run (an agent that is neither the entry agent nor used as a tool), on_trip: hil on an output guardrail, and bad entries. Before 1.35.0 an application could not attach its own guardrails at all. Tests: tests/test_openai_guardrails.py. current_run_config() (k9_adapters.openai_agents): a guardrail that runs an agent of its own passes it to Runner.run, so the check's model call is routed by the K9 Model Router on the run's provider. Without it the nested run used the SDK's default provider (OpenAI) and, on Ollama, failed on the second step with "Event loop is closed". Verified with the guide's churn guardrail on qwen2.5:7b: a greeting answered, a cancellation sent to the retention queue with the check's reasoning. An SDK coverage table in k9_adapters/openai_agents/CLAUDE.md: every OpenAI Agents SDK feature, supported, mapped (to what), not supported, or refused on purpose (with the K9 check it would bypass). k9_utils/step_outputs.py: parse_json_text, resolve_path, with_parsed_outputs. K9OpenAIAgent's approval policy uses the same helper (it had its own copy; it now parses only JSON objects and lists, never a reply that happens to be a number or true). tests/test_structured_output_conditions.py: the helper, squad when:, rules on structured fields, every engine getting parsed facts, and OpenAI's churn guardrail end to end as a squad (ChurnDetectionAgent → K9RulesAgent → CustomerSupportAgent): a churn risk raises RequiresHIL on the retention queue and the support agent never runs; a greeting is answered. [1.34.0] — 2026-11-20 Fixed (security) Granite Guardian screened only part of what it was given. GuardianGovernance sent the model only the first 4000 characters (both the default check and every named risk), read only the first matching key (query, document_text, text), and fell back to str(payload)[:2000] when none matched. A document under any other key (DAS passes source_markdown) was screened for roughly its first 2000 characters, and an instruction on page 3 of a submitted document was never seen. Found 2026-11-20: DAS's attack documents passed the demo only because each was just under 4000 characters long. Now every string in the payload is screened (the conventional keys first, then every other value, nested ones included; _k9* stamps skipped), all of it: the text is split into overlapping chunks and each is classified; any UNSAFE chunk blocks, and the reason names the chunk. Text over max_chars (default 120000) is treated as an unavailable check: refused under the default fail_closed, never passed as screened. Added governance.guardian settings: chunk_chars (2000), chunk_overlap (200), max_chars (120000), cache_size (4096). Default chunk size measured against granite4.1-guardian:8b: a one-line hidden instruction placed after a benign document was missed at 4000-character chunks and caught at 2000 (three runs each); four benign documents up to 32,108 characters passed. A process-wide cache of chunks judged SAFE (by model, temperature, check and sha256), so a document carried through many agents is classified once. UNSAFE and UNAVAILABLE are never cached. k9_factories.reset_all() clears it (clear_safe_cache()). Each string in the payload is chunked on its own, so a document has the same chunks in every payload it travels in, whatever fields sit beside it. Strings under 512 characters (a message, ids, a role) are packed into one unit, so ten small fields cost one call, not ten. concurrency (4): the default check and every named risk, on every chunk, run in one pool of that many calls; the first UNSAFE cancels the calls not yet started. Each call runs in a copy of the caller's context, so its trace events keep the run's trace id. Measured against granite4.1-guardian:8b (a 32,012-character document through 5 agents, default check plus process_manipulation): 198 calls / 419 s screening everything in every agent, 54 calls / 117 s with the per-string chunks and the cache. Concurrency adds speed only when the model server runs requests in parallel (Ollama: OLLAMA_NUM_PARALLEL); on a server that serves one at a time the calls queue. k9x Shield reads every value at every depth. Each check had its own helper that stopped at depth 8 (ToolArgumentCheck at 6) and returned nothing below it: an injection nested 9 levels deep passed every check, and InputSizeCheck didn't count it. One shared walker now (k9_security/vulnerability/payload_text.py): iterative, no depth limit, a reference cycle read once. Tests: test_shield_reads_every_depth_1_34.py. governance.guardian.required (enterprise lock): written in the config file; with Guardian off (from .env or unset), governance_from_config raises GovernanceConfigError outside development/test. K9_GUARDIAN_ENABLED: the shipped config reads governance.guardian.enabled: ${K9_GUARDIAN_ENABLED:-false}, one switch name for every application. governance.guardian.points (all by default): where the model-based check is spent. A caller names its check point in ctx["checkpoint"]; the OpenAI adapter labels every check (ingress, reply, handoff, tool_call, tool_result, egress). A point not listed is skipped by Guardian only, with a GuardianSkipped trace event; Shield runs at every point. A call with no checkpoint (every agent's own input and output) is always screened. In a group of agents a reply is a handoff point. Config ${VAR:-default}: an empty value takes the default, as in the shell. A blank VAR= line in a .env file used to pass an empty string on (an empty model name, an empty URL). Changed Guardian makes more model calls on long payloads (one per chunk per check). Cost grows with text length; max_chars bounds it. Tests: test_guardian_whole_text_1_34.py (19). [1.33.0] — 2026-11-20 Added OpenAI Manager pattern (agents as tools) in the OOB OpenAIAgentsOrchestratorAdapter. A new agent YAML key, agent_tools: [SpanishAgent, FrenchAgent], gives that agent the named agents as tools (Agent.as_tool): its model decides which to call, gets each answer back, and writes the one reply itself; specialists never answer the user. This is the pattern OpenAI's "A practical guide to building agents" calls Manager; handoffs (Decentralized) and a K9 squad of K9OpenAIAgent steps (orchestrating via code) were already supported. Each delegation is governed like any tool call: Shield on what the manager sends (screen_tool_call) and on what comes back (s
Authors: k9aif, ravinata-ibm
Language: English
Subfield: Artificial Intelligence
Field: Computer Science
Domain: Physical Sciences
Open Access status: green
OpenAlex ID: W7204098780
