Add chat triggers#29
Conversation
…ons-afm into add-chat-triggers
Previously we used thread_name to generate the session_id. However, each gchat message has its own thread thereby giving all messages a new session with the agent. We can consider supporting replying within thread later. Until then lets use space_name:user_name as the default session_id temp Fix tests after prev fix
Fix validation logic for gchat trigger
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughThis pull request introduces a complete "platformchat" interface feature to the AFM framework, enabling bidirectional agent communication with chat platforms (Slack and Google Chat). The implementation spans model definitions, handler abstractions, platform-specific integrations with signature verification, FastAPI routing for both asynchronous notification and synchronous request/response modes, CLI integration, comprehensive test coverage, and infrastructure refactoring. Version dependencies are updated across Ballerina and Python interpreters, and the Docker runtime is migrated to Alpine-based Temurin with compatibility libraries. Suggested reviewers
🚥 Pre-merge checks | ✅ 2 | ❌ 3❌ Failed checks (2 warnings, 1 inconclusive)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Pull request overview
This PR introduces a new platformchat AFM interface to trigger agents from third‑party chat platforms (initially Slack + Google Chat), including signature/bearer verification and session-id derivation, and wires it into the CLI/unified HTTP app.
Changes:
- Add
PlatformChatInterface+ per-platform handlers (Slack/GChat) and FastAPI router/app factory forplatformchat. - Extend CLI parsing/validation/run to recognize and serve the new interface; add extensive unit + integration tests and AFM fixtures.
- Update webhook execution to pass
session_idintoagent.arun, and update Ballerina interpreter packaging/runtime dependencies.
Reviewed changes
Copilot reviewed 23 out of 24 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| templates/agent_template.afm.md | Adds a platformchat example to the AFM template. |
| python-interpreter/packages/afm-core/tests/test_webhook.py | Minor test cleanup for webhook tests. |
| python-interpreter/packages/afm-core/tests/test_platform_chat.py | New unit tests for platformchat handlers/router behavior. |
| python-interpreter/packages/afm-core/tests/test_platform_chat_integration.py | New integration tests using a real runner + fake LLM. |
| python-interpreter/packages/afm-core/tests/test_parser.py | Parser coverage for platformchat + some additional schema validation tests. |
| python-interpreter/packages/afm-core/tests/test_cli.py | CLI validate coverage for platformchat config validation. |
| python-interpreter/packages/afm-core/tests/fixtures/sample_slack_platform_chat_agent.afm.md | New Slack platformchat AFM fixture. |
| python-interpreter/packages/afm-core/tests/fixtures/sample_gchat_platform_chat_sync_agent.afm.md | New GChat request-mode AFM fixture. |
| python-interpreter/packages/afm-core/tests/fixtures/sample_gchat_platform_chat_agent.afm.md | New GChat notification-mode AFM fixture. |
| python-interpreter/packages/afm-core/tests/conftest.py | Adds fixtures to locate new platformchat AFM samples. |
| python-interpreter/packages/afm-core/src/afm/variables.py | Extends HTTP-variable validation to cover platformchat fields. |
| python-interpreter/packages/afm-core/src/afm/models.py | Adds PlatformChatInterface/PlatformChatMode and tightens Subscription protocol type. |
| python-interpreter/packages/afm-core/src/afm/interfaces/webhook.py | Refactors prompt building; passes session_id to agent; adjusts signature verification behavior. |
| python-interpreter/packages/afm-core/src/afm/interfaces/platform_chat/slack.py | Implements Slack config, signature verification, ignore logic, session-id derivation. |
| python-interpreter/packages/afm-core/src/afm/interfaces/platform_chat/gchat.py | Implements GChat config, JWT verification, ignore logic, session-id derivation. |
| python-interpreter/packages/afm-core/src/afm/interfaces/platform_chat/_handler.py | Defines the platform handler abstraction. |
| python-interpreter/packages/afm-core/src/afm/interfaces/platform_chat/init.py | Implements platformchat router/app and handler registry. |
| python-interpreter/packages/afm-core/src/afm/interfaces/base.py | Adds platformchat interface lookup + path resolution support. |
| python-interpreter/packages/afm-core/src/afm/cli.py | Adds platformchat support to validate/run/unified app. |
| python-interpreter/packages/afm-core/pyproject.toml | Adds PyJWT dependency for GChat bearer verification. |
| ballerina-interpreter/Dockerfile | Switches runtime base image to Alpine Temurin and installs compat libs. |
| ballerina-interpreter/Dependencies.toml | Updates Ballerina dependency versions. |
| ballerina-interpreter/Ballerina.toml | Bumps Ballerina package version. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@python-interpreter/packages/afm-core/src/afm/interfaces/platform_chat/slack.py`:
- Around line 66-76: The current signature check builds sig_basestring using
body.decode('utf-8') which can raise UnicodeDecodeError and produce a 500;
change the logic in the block that constructs sig_basestring/expected_sig
(references: sig_basestring, expected_sig, SLACK_SIGNATURE_VERSION,
signing_secret, signature_header) to handle invalid UTF-8 by either decoding
with a safe error handler (e.g., errors='replace' or 'ignore') or by wrapping
the decode in a try/except that treats decode failures as a verification failure
and returns False, then proceed to compute expected_sig and call
hmac.compare_digest as before.
In `@python-interpreter/packages/afm-core/src/afm/variables.py`:
- Around line 178-194: The validation currently allows http: in
PlatformChatInterface.prompt but the aggregated error message still states only
webhook prompt fields support http: variables; update the error text emitted
where you build messages from errored_fields so it mentions platformchat.prompt
(and/or "interfaces.platformchat.signature") in addition to webhook prompt
fields. Locate the block handling PlatformChatInterface (symbols:
PlatformChatInterface, _signature_contains_http_variable, errored_fields) and
revise the user-facing validation message construction to include platformchat
prompt support.
In `@python-interpreter/packages/afm-core/tests/test_parser.py`:
- Around line 222-240: The test_websub_rejects_unknown_fields currently builds a
minimal webhook config that could fail for unrelated validation reasons; update
the content string in that test so the rest of the AFM is explicitly valid
(e.g., include required fields for a webhook/interface and any top-level fields
needed by parse_afm) and then change the with pytest.raises(AFMValidationError):
block to capture the exception (e.g., as err) and assert "provider" (or the
exact unexpected field name) appears in str(err) to ensure the failure is
specifically about the unknown "provider" field when calling parse_afm.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 0fbb99cc-682e-40cc-bc93-e0c7dc78e863
⛔ Files ignored due to path filters (1)
python-interpreter/uv.lockis excluded by!**/*.lock
📒 Files selected for processing (23)
ballerina-interpreter/Ballerina.tomlballerina-interpreter/Dependencies.tomlballerina-interpreter/Dockerfilepython-interpreter/packages/afm-core/pyproject.tomlpython-interpreter/packages/afm-core/src/afm/cli.pypython-interpreter/packages/afm-core/src/afm/interfaces/base.pypython-interpreter/packages/afm-core/src/afm/interfaces/platform_chat/__init__.pypython-interpreter/packages/afm-core/src/afm/interfaces/platform_chat/_handler.pypython-interpreter/packages/afm-core/src/afm/interfaces/platform_chat/gchat.pypython-interpreter/packages/afm-core/src/afm/interfaces/platform_chat/slack.pypython-interpreter/packages/afm-core/src/afm/interfaces/webhook.pypython-interpreter/packages/afm-core/src/afm/models.pypython-interpreter/packages/afm-core/src/afm/variables.pypython-interpreter/packages/afm-core/tests/conftest.pypython-interpreter/packages/afm-core/tests/fixtures/sample_gchat_platform_chat_agent.afm.mdpython-interpreter/packages/afm-core/tests/fixtures/sample_gchat_platform_chat_sync_agent.afm.mdpython-interpreter/packages/afm-core/tests/fixtures/sample_slack_platform_chat_agent.afm.mdpython-interpreter/packages/afm-core/tests/test_cli.pypython-interpreter/packages/afm-core/tests/test_parser.pypython-interpreter/packages/afm-core/tests/test_platform_chat.pypython-interpreter/packages/afm-core/tests/test_platform_chat_integration.pypython-interpreter/packages/afm-core/tests/test_webhook.pytemplates/agent_template.afm.md
💤 Files with no reviewable changes (1)
- python-interpreter/packages/afm-core/tests/test_webhook.py
ba1da7e to
0d6f50e
Compare
Add telegram platformchat support - polling and notification modes
Purpose
$title.