- Remove dead ContextVar code from token_tracking.py (was never set)
- Replace orphaned get_token_stats() with instance method get_stats()
- Add proper exports to workflows/__init__.py (SubIterationMiddleware, etc.)
- Clean up imports in huggingface.py (use package import)
- Add type: ignore for mypy list invariance issue
All 311 tests pass.
## Summary
Fixes P1 bug where Free Tier tool calls were never executed because `@use_function_invocation` decorator was skipped.
## Root Cause
`HuggingFaceChatClient` had `__function_invoking_chat_client__ = True` in class body, causing decorator early return.
## Changes
- Remove premature marker from `src/clients/huggingface.py`
- Add `docs/architecture/system_registry.md` as canonical SSOT for wiring
- Document P1 root cause analysis
- Address all CodeRabbit review findings
## Impact
- Free Tier tool execution now works correctly
- P2 7B garbage output superseded (was symptom, not cause)
fix(P1): Replace stale 72B model fallbacks with 7B to avoid Novita 500 errorsβ
Claude
Unverified signature
a4327d1
Bug: Three files had hardcoded fallbacks to Qwen2.5-72B-Instruct which
routes to Novita provider (unreliable, 500 errors). The config.py was
updated to use 7B, but these fallbacks were stale.
Files fixed:
- src/clients/huggingface.py:59 - HuggingFaceChatClient init
- src/agent_factory/judges.py:85 - get_model() HuggingFace branch
- src/orchestrators/langgraph_orchestrator.py:43 - LangGraph init (deprecated)
All fallbacks now use Qwen/Qwen2.5-7B-Instruct to stay on HuggingFace
native serverless infrastructure (models < 30B params).
See: CLAUDE.md "CRITICAL: HuggingFace Free Tier Architecture" section
All 310 unit tests pass.
fix(P0): Auto-detect OpenAI provider from BYOK api_key prefixβ
Claude
Unverified signature
e4c6475
Bug: When users entered an OpenAI key (sk-...) in Gradio without
a provider parameter, the client factory only checked settings.has_openai_key
(env var) and fell through to HuggingFace, causing V1 chat completion errors.
Fix: Add provider auto-detection from api_key prefix in get_chat_client():
- sk-ant-... β Anthropic (NotImplementedError - not yet supported)
- sk-... β OpenAI (now correctly routed)
- hf_... β Falls through to HuggingFace (default)
Order matters: "sk-ant-" must be checked before "sk-" since both share prefix.
Tests added:
- test_byok_auto_detects_openai_from_key_prefix (the critical fix test)
- test_byok_auto_detects_anthropic_from_key_prefix
- test_byok_hf_token_falls_through_to_huggingface
- test_anthropic_provider_raises_not_implemented
All 310 unit tests pass.
Changes based on CodeRabbit PR review:
1. docs/bugs/P0_HUGGINGFACE_TOOL_CALLING_BROKEN.md:
- Add 'text' language to fenced code block (MD040)
- Wrap bare GitHub URL in markdown link (MD034)
- Update workaround section to reflect implementation status
2. src/orchestrators/advanced.py:
- Add plain string handling to _extract_text() for WorkflowOutputEvent.data
- Filter repr-style noise from string payloads
3. src/clients/huggingface.py:
- JSON-encode structured tool results instead of str()
- Track call_id -> name mapping for tool result messages
- Add 'name' field to tool messages (required by some APIs)
Changes:
1. Add __function_invoking_chat_client__ marker to HuggingFaceChatClient
- Without this marker, agent_framework ignores tools passed to the client
- The warning "does not support function invoking" is now eliminated
2. Improve _extract_text in AdvancedOrchestrator:
- Handle ChatMessage.contents (list of FunctionCallContent, TextContent)
- Extract tool call names when text content is empty
- Return empty string instead of object repr for graceful fallback
3. Fix WorkflowOutputEvent handling:
- Use _extract_text instead of str() to avoid object repr in output
- Provide meaningful fallback message when no text available
These fixes ensure the HuggingFace Free Tier can properly:
- Declare function calling capability to the framework
- Display tool calls and text content in events
- Show clean output instead of <ChatMessage object at ...>
fix(P0): Complete bi-directional tool support for HuggingFace (sync+streaming)
Reverts unnecessary over-engineering from previous "fix(auth)" commit.
Root cause: HF_TOKEN in .env was invalid/expired, not infrastructure issues.
Resolution:
- Generated new valid HF_TOKEN
- Keep Qwen/Qwen2.5-72B model change (good for reliability)
- Updated bug doc with actual root cause and lessons learned
The Pydantic settings alias="HF_TOKEN" works correctly - no need
for os.environ.get() hacks or extra debug logging.
fix(auth): Robust HF_TOKEN loading and debug logging for Partner API auth failure