Skip to content

Add chat triggers#29

Draft
MaryamZi wants to merge 18 commits into
mainfrom
add-chat-triggers
Draft

Add chat triggers#29
MaryamZi wants to merge 18 commits into
mainfrom
add-chat-triggers

Conversation

@MaryamZi

Copy link
Copy Markdown
Member

Purpose

$title.

MaryamZi and others added 13 commits April 28, 2026 15:13
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
@coderabbitai

coderabbitai Bot commented May 21, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9ebc282f-062c-4212-ad87-1dc1c3d02052

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

This 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

  • Copilot
  • RadCod3
  • MohamedSabthar
  • lnash94
🚥 Pre-merge checks | ✅ 2 | ❌ 3

❌ Failed checks (2 warnings, 1 inconclusive)

Check name Status Explanation Resolution
Description check ⚠️ Warning The pull request description is largely incomplete, containing only 'Purpose: $title.' with no substantive information about the changes, objectives, or approach. Complete the description by filling in all required template sections: Goals, Approach, User stories, Release note, Documentation, Training, Certification, Marketing, test coverage, Security checks, Samples, Related PRs, and Test environment details.
Docstring Coverage ⚠️ Warning Docstring coverage is 7.92% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'Add chat triggers' is vague and generic, using non-descriptive phrasing that does not clearly convey the specific changes introduced. Revise the title to be more specific about the feature, such as 'Add platform-agnostic chat interface for Slack and Google Chat' or similar wording that clarifies the main addition.
✅ Passed checks (2 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch add-chat-triggers

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@MaryamZi

Copy link
Copy Markdown
Member Author

@coderabbitai review

@MaryamZi MaryamZi requested a review from Copilot May 21, 2026 10:02
@coderabbitai

coderabbitai Bot commented May 21, 2026

Copy link
Copy Markdown
Contributor
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 for platformchat.
  • 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_id into agent.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.

Comment thread python-interpreter/packages/afm-core/src/afm/interfaces/platform_chat/__init__.py Outdated
Comment thread python-interpreter/packages/afm-core/src/afm/interfaces/base.py
Comment thread templates/agent_template.afm.md Outdated
Comment thread python-interpreter/packages/afm-core/src/afm/interfaces/webhook.py

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9c1fd1c and ffa85a1.

⛔ Files ignored due to path filters (1)
  • python-interpreter/uv.lock is excluded by !**/*.lock
📒 Files selected for processing (23)
  • ballerina-interpreter/Ballerina.toml
  • ballerina-interpreter/Dependencies.toml
  • ballerina-interpreter/Dockerfile
  • python-interpreter/packages/afm-core/pyproject.toml
  • python-interpreter/packages/afm-core/src/afm/cli.py
  • python-interpreter/packages/afm-core/src/afm/interfaces/base.py
  • python-interpreter/packages/afm-core/src/afm/interfaces/platform_chat/__init__.py
  • python-interpreter/packages/afm-core/src/afm/interfaces/platform_chat/_handler.py
  • python-interpreter/packages/afm-core/src/afm/interfaces/platform_chat/gchat.py
  • python-interpreter/packages/afm-core/src/afm/interfaces/platform_chat/slack.py
  • python-interpreter/packages/afm-core/src/afm/interfaces/webhook.py
  • python-interpreter/packages/afm-core/src/afm/models.py
  • python-interpreter/packages/afm-core/src/afm/variables.py
  • python-interpreter/packages/afm-core/tests/conftest.py
  • python-interpreter/packages/afm-core/tests/fixtures/sample_gchat_platform_chat_agent.afm.md
  • python-interpreter/packages/afm-core/tests/fixtures/sample_gchat_platform_chat_sync_agent.afm.md
  • python-interpreter/packages/afm-core/tests/fixtures/sample_slack_platform_chat_agent.afm.md
  • python-interpreter/packages/afm-core/tests/test_cli.py
  • python-interpreter/packages/afm-core/tests/test_parser.py
  • python-interpreter/packages/afm-core/tests/test_platform_chat.py
  • python-interpreter/packages/afm-core/tests/test_platform_chat_integration.py
  • python-interpreter/packages/afm-core/tests/test_webhook.py
  • templates/agent_template.afm.md
💤 Files with no reviewable changes (1)
  • python-interpreter/packages/afm-core/tests/test_webhook.py

Comment thread python-interpreter/packages/afm-core/src/afm/interfaces/platform_chat/slack.py Outdated
Comment thread python-interpreter/packages/afm-core/src/afm/variables.py
Comment thread python-interpreter/packages/afm-core/tests/test_parser.py
@MaryamZi MaryamZi force-pushed the add-chat-triggers branch from ba1da7e to 0d6f50e Compare May 25, 2026 09:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants