fix(ag2): code cleanup and CI/release integration (#721)

- Remove unnecessary `pass` in HindsightError
- Add `Callable` return type annotations to create/register functions
- Use lazy logger formatting instead of f-strings
- Add test-ag2-integration CI job in test.yml
- Add ag2 to release-integration.sh valid integrations
This commit is contained in:
Nicolò Boschi 2026-03-27 10:10:14 +01:00 committed by GitHub
parent 083295dc6f
commit e5c7e166c5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 45 additions and 9 deletions

View file

@ -35,6 +35,7 @@ jobs:
integrations-crewai: ${{ steps.filter.outputs.integrations-crewai }} integrations-crewai: ${{ steps.filter.outputs.integrations-crewai }}
integrations-litellm: ${{ steps.filter.outputs.integrations-litellm }} integrations-litellm: ${{ steps.filter.outputs.integrations-litellm }}
integrations-pydantic-ai: ${{ steps.filter.outputs.integrations-pydantic-ai }} integrations-pydantic-ai: ${{ steps.filter.outputs.integrations-pydantic-ai }}
integrations-ag2: ${{ steps.filter.outputs.integrations-ag2 }}
integrations-hermes: ${{ steps.filter.outputs.integrations-hermes }} integrations-hermes: ${{ steps.filter.outputs.integrations-hermes }}
dev: ${{ steps.filter.outputs.dev }} dev: ${{ steps.filter.outputs.dev }}
ci: ${{ steps.filter.outputs.ci }} ci: ${{ steps.filter.outputs.ci }}
@ -94,6 +95,8 @@ jobs:
- 'hindsight-integrations/litellm/**' - 'hindsight-integrations/litellm/**'
integrations-pydantic-ai: integrations-pydantic-ai:
- 'hindsight-integrations/pydantic-ai/**' - 'hindsight-integrations/pydantic-ai/**'
integrations-ag2:
- 'hindsight-integrations/ag2/**'
integrations-hermes: integrations-hermes:
- 'hindsight-integrations/hermes/**' - 'hindsight-integrations/hermes/**'
dev: dev:
@ -1487,6 +1490,40 @@ jobs:
echo "=== API Server Logs ===" echo "=== API Server Logs ==="
cat /tmp/api-server.log || echo "No API server log found" cat /tmp/api-server.log || echo "No API server log found"
test-ag2-integration:
needs: [detect-changes]
if: >-
github.event_name == 'workflow_dispatch' ||
needs.detect-changes.outputs.integrations-ag2 == 'true' ||
needs.detect-changes.outputs.ci == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Install uv
uses: astral-sh/setup-uv@v7
with:
enable-cache: true
prune-cache: false
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version-file: ".python-version"
- name: Build ag2 integration
working-directory: ./hindsight-integrations/ag2
run: uv build
- name: Install dependencies
working-directory: ./hindsight-integrations/ag2
run: uv sync --frozen
- name: Run tests
working-directory: ./hindsight-integrations/ag2
run: uv run pytest tests -v
test-crewai-integration: test-crewai-integration:
needs: [detect-changes] needs: [detect-changes]
if: >- if: >-

View file

@ -3,5 +3,3 @@
class HindsightError(Exception): class HindsightError(Exception):
"""Exception raised when a Hindsight memory operation fails.""" """Exception raised when a Hindsight memory operation fails."""
pass

View file

@ -7,6 +7,7 @@ functions with ``Annotated`` type hints, compatible with AG2's
""" """
import logging import logging
from collections.abc import Callable
from typing import Annotated, Any, Optional from typing import Annotated, Any, Optional
from hindsight_client import Hindsight from hindsight_client import Hindsight
@ -44,7 +45,7 @@ def create_hindsight_tools(
include_retain: bool = True, include_retain: bool = True,
include_recall: bool = True, include_recall: bool = True,
include_reflect: bool = True, include_reflect: bool = True,
) -> list: ) -> list[Callable]:
"""Create Hindsight memory tools for AG2 agents. """Create Hindsight memory tools for AG2 agents.
Returns a list of plain Python functions compatible with AG2's Returns a list of plain Python functions compatible with AG2's
@ -110,7 +111,7 @@ def create_hindsight_tools(
else (config.max_tokens if config else 4096) else (config.max_tokens if config else 4096)
) )
tools: list = [] tools: list[Callable] = []
if include_retain: if include_retain:
@ -137,7 +138,7 @@ def create_hindsight_tools(
resolved_client.retain(**retain_kwargs) resolved_client.retain(**retain_kwargs)
return "Memory stored successfully." return "Memory stored successfully."
except Exception as e: except Exception as e:
logger.error(f"Retain failed: {e}") logger.error("Retain failed: %s", e)
raise HindsightError(f"Retain failed: {e}") from e raise HindsightError(f"Retain failed: {e}") from e
tools.append(hindsight_retain) tools.append(hindsight_retain)
@ -177,7 +178,7 @@ def create_hindsight_tools(
lines.append(f"{i}. {result.text}") lines.append(f"{i}. {result.text}")
return "\n".join(lines) return "\n".join(lines)
except Exception as e: except Exception as e:
logger.error(f"Recall failed: {e}") logger.error("Recall failed: %s", e)
raise HindsightError(f"Recall failed: {e}") from e raise HindsightError(f"Recall failed: {e}") from e
tools.append(hindsight_recall) tools.append(hindsight_recall)
@ -221,7 +222,7 @@ def create_hindsight_tools(
response = resolved_client.reflect(**reflect_kwargs) response = resolved_client.reflect(**reflect_kwargs)
return response.text or "No relevant memories found." return response.text or "No relevant memories found."
except Exception as e: except Exception as e:
logger.error(f"Reflect failed: {e}") logger.error("Reflect failed: %s", e)
raise HindsightError(f"Reflect failed: {e}") from e raise HindsightError(f"Reflect failed: {e}") from e
tools.append(hindsight_reflect) tools.append(hindsight_reflect)
@ -235,7 +236,7 @@ def register_hindsight_tools(
*, *,
bank_id: str, bank_id: str,
**kwargs, **kwargs,
) -> list: ) -> list[Callable]:
"""Convenience: create tools AND register them on AG2 agents. """Convenience: create tools AND register them on AG2 agents.
Creates Hindsight memory tools and registers them on the given AG2 Creates Hindsight memory tools and registers them on the given AG2

View file

@ -13,7 +13,7 @@ print_info() { echo -e "${GREEN}[INFO]${NC} $1"; }
print_warn() { echo -e "${YELLOW}[WARN]${NC} $1"; } print_warn() { echo -e "${YELLOW}[WARN]${NC} $1"; }
print_error() { echo -e "${RED}[ERROR]${NC} $1"; } print_error() { echo -e "${RED}[ERROR]${NC} $1"; }
VALID_INTEGRATIONS=("litellm" "pydantic-ai" "crewai" "ai-sdk" "chat" "openclaw" "langgraph" "nemoclaw" "strands" "claude-code") VALID_INTEGRATIONS=("litellm" "pydantic-ai" "crewai" "ag2" "ai-sdk" "chat" "openclaw" "langgraph" "nemoclaw" "strands" "claude-code")
usage() { usage() {
print_error "Usage: $0 <integration> <version>" print_error "Usage: $0 <integration> <version>"