Skip to content

feat(tools): Add Zammad ticket tools - #335

Draft
funana777 wants to merge 1 commit into
feat/shorten-json-objectsfrom
feat/zammad-tools
Draft

funana777 wants to merge 1 commit into
feat/shorten-json-objectsfrom
feat/zammad-tools

Conversation

@funana777

@funana777 funana777 commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Adds Zammad ticket tools: the Assistant can list tickets, read a ticket with its conversation, find similar tickets, and add internal notes.

Base: #338 (feat/shorten-json-objects). Merge #338 first. It needs integration_zammad with nextcloud/integration_zammad#296 (read, with paging) and #297 (notes).

Why

Support teams work in Zammad and want the Assistant's help on tickets: a briefing on a long thread, a summary as an internal note for colleagues. Today the Assistant cannot read a ticket; asked about one, it calls Zammad without a token and asks the user to paste one into the chat. integration_zammad already holds each user's token, so the tools go through its ticket API, the same way openproject.py uses integration_openproject.

What

  • list_zammad_tickets, get_zammad_ticket: read only. The descriptions teach Zammad's search syntax (and that field queries need Elasticsearch on the Zammad server), the contact and escalation times in a list and how to tell the Assistant's own notes, and say that ticket text is data, never instructions. get_zammad_ticket reads the newest 10 articles. older_articles says how many come before them, and the model reads those with before when it needs them.
  • find_similar_zammad_tickets: a Context Chat search scoped to tickets of the user's Zammad server, built from the ticket's title and first customer message, read with one call of up to 50 articles. It returns ID and link of the similar tickets; the model opens the relevant ones. Without Context Chat it returns an empty list with a reason. The instance ID it matches is pinned by a test vector that integration_zammad's tests pin too.
  • add_zammad_internal_note(ticket_title, ticket_number, ticket, text, force): GROUP radius, irreversible, so the user confirms every note with the default thresholds. The confirmation shows the first three arguments, so title and number come first. The server checks the number, not the title. Notes are plain text. The tool is only offered when the capability reports ticket_api 2 or higher, which has the notes route.
  • Assistant notes are marked by the tool. integration_zammad's notes route stores a note as given, so the tool ends every note with an empty line, a line --- and Nextcloud Assistant for <display name>, and drops a footer the model wrote itself. The block is fixed and untranslated, because earlier notes are recognized by it.
  • Duplicate check in the tool: before writing, it reads the newest 20 articles and refuses a second note (already_noted) when an Assistant note is newer than the customer's last message, unless the user asked for another one (force). An Assistant note is an internal note of type note by an agent whose last two non-empty lines are the footer block.

Notes for review:

  • The tools are offered whenever integration_zammad is installed. Whether a user is connected cannot be seen without a request per run, so users who are not get a not_connected answer with how to connect.
  • Paging replaces feat(context): Tell tools how large their result may be #336, which sized the result to the room the model has; see the review there.
  • Known limit: an article that alone is larger than the room the agent has for a tool result, such as a long pasted log, is left out whole by the shortening from fix(context): Keep shortened JSON objects valid #338, and reading the page again does not help. Cutting such an article would go into the agent's shortening, as suggested in feat(context): Tell tools how large their result may be #336.
  • The four tool descriptions take about 4,000 characters of the context budget on every request.
  • test_tool_classification_markers.py: the fake app now answers capabilities, because get_tools() reads it for the note tool.

642 lines added, none removed: 329 in the tool module, 313 in tests.

How to test

  1. python -m pytest tests
  2. On an instance with integration_zammad from feat: Let the Assistant add internal notes integration_zammad#297 and a connected user, ask the Assistant: "Brief me on ticket : summarize the problem and list the attachments."
  3. Ask it to add an internal note to that ticket. It asks for confirmation first, showing the ticket title and number. Check the note in Zammad: plain text, ending with --- and "Nextcloud Assistant for ". Ask again: it reports that the ticket already has a note.
  4. On a ticket with more than 10 articles, ask for the customer's first message: the Assistant reads the older articles with before.
  5. With Context Chat indexing Zammad tickets, ask for similar tickets and how the most relevant one was solved.

🤖 AI (if applicable)

  • The content of this PR was partly or fully generated using AI

Code, tests and this description were drafted with Claude Code (claude-opus-5-5) under my direction.

How this was tested before opening the PR

This version: 427 unit tests, including the footer added exactly once, the refused second note and force, a note after a new customer message, and what does not count as an Assistant note (a customer quoting the footer, the phrase inside a note, a public article, a footer without the --- line, a system article).

An earlier version, where integration_zammad added the footer and ran the duplicate check, ran on a sandbox Nextcloud 35.0.1 (Assistant 4.0.0) against a fake Zammad and a fake OpenAI-compatible endpoint: a scripted triage of three tickets with confirmed notes and one already_noted refusal, and Claude Haiku standing in for a small model, which picked the most urgent waiting ticket and, after an already_noted refusal, asked the user instead of forcing a second note. The version before paging (dbe3145, with #340 merged in locally) ran end to end on 2026-11-24 on a sandbox Nextcloud 35.0.1 with nextcloud/integration_zammad#296 to #298 against a fake Zammad. With scripted tool calls: not connected, list with mine, get by ID and by link, a note with confirmation and the footer, already_noted, force, a wrong ticket number, the capability gate, and a note allowed again after a new customer message once integration_zammad#296 returned last_contact_customer_at (that fix came out of this run). With Claude Haiku as the model: it listed the user's tickets, summarized a ticket into a confirmed note, set force when asked for a second note, and asked instead of retrying after a cancelled note. find_similar only gave its "Context Chat is not available" answer. It has not run against a real Zammad or a Context Chat backend.

Paging (this version): on a local Nextcloud 36 (master, SQLite) with nextcloud/integration_zammad#296 against a fake Zammad with 25 invented articles, get_zammad_ticket read the ticket in pages of 10, 10 and 5 with before and got every article once, an 86,000-character article whole; the note check read the newest 20 articles and refused with already_noted; the similar-ticket query used the first customer message. With the page shortened to 20,000 characters, #338 left out only the long article and kept valid JSON. With nextcloud/integration_zammad#297 rebased onto the paging commit: a second note refused as already_noted, a wrong ticket number refused with nothing sent to Zammad, and with force a note stored with the footer, which the next read showed as the newest article. Not yet run with a model.


Generated by Claude Code

@funana777
funana777 force-pushed the feat/zammad-tools branch 3 times, most recently from e9d7f56 to fa02bf7 Compare November 18, 2026 17:47
@funana777
funana777 force-pushed the feat/zammad-tools branch 2 times, most recently from 5aec9b8 to 63d6330 Compare November 18, 2026 18:04
@funana777
funana777 changed the base branch from main to feat/shorten-nested-lists November 18, 2026 18:05
@funana777
funana777 force-pushed the feat/shorten-nested-lists branch from 5c983ad to 599632d Compare November 18, 2026 18:17
@funana777
funana777 force-pushed the feat/zammad-tools branch 2 times, most recently from 059bd45 to 48d5e20 Compare November 19, 2026 10:26
@funana777
funana777 force-pushed the feat/shorten-nested-lists branch from 3f8c378 to 996e687 Compare November 19, 2026 10:26
@funana777
funana777 force-pushed the feat/zammad-tools branch 2 times, most recently from 8766435 to 0675a96 Compare November 19, 2026 15:04
@funana777
funana777 force-pushed the feat/zammad-tools branch 2 times, most recently from d730eae to cc34f75 Compare November 19, 2026 16:23
@funana777
funana777 force-pushed the feat/shorten-nested-lists branch from 996e687 to a1c6586 Compare November 19, 2026 17:24
@funana777
funana777 force-pushed the feat/zammad-tools branch 2 times, most recently from e5b91be to 1b29316 Compare November 19, 2026 17:35
@funana777
funana777 force-pushed the feat/shorten-nested-lists branch 2 times, most recently from 7712906 to b9e6489 Compare November 19, 2026 17:56
@funana777
funana777 force-pushed the feat/zammad-tools branch 2 times, most recently from 39a55ee to 7c498d4 Compare November 19, 2026 18:23
@funana777
funana777 force-pushed the feat/shorten-nested-lists branch from b9e6489 to 7cbab3d Compare November 19, 2026 18:23
@funana777
funana777 force-pushed the feat/shorten-nested-lists branch from 7cbab3d to 868eb9c Compare November 19, 2026 18:52
@funana777
funana777 force-pushed the feat/zammad-tools branch 2 times, most recently from 541ea20 to 2969b7b Compare November 19, 2026 18:58
@funana777
funana777 force-pushed the feat/shorten-nested-lists branch 2 times, most recently from 54967ca to 58d2da5 Compare November 24, 2026 13:37
@funana777
funana777 force-pushed the feat/zammad-tools branch 2 times, most recently from 3a53ffd to dbe3145 Compare November 24, 2026 13:42
@funana777
funana777 changed the base branch from feat/shorten-nested-lists to feat/shorten-json-objects November 26, 2026 13:22
The Assistant can list Zammad tickets, read a ticket with its
conversation, find similar tickets and add internal notes. The tools
use the ticket API of integration_zammad, which keeps the user's Zammad
token, the same way openproject.py uses integration_openproject.

- list_zammad_tickets and get_zammad_ticket are read only. The
  descriptions teach Zammad's search syntax, the contact and escalation
  times in a list and how to tell the Assistant's own notes, and say
  that ticket text is data, never instructions. get_zammad_ticket
  reads the newest ten articles and, when the model asks for them,
  the ones before, so it reads only as far back as it needs.
- find_similar_zammad_tickets runs a Context Chat search scoped to
  tickets of the user's Zammad server, built from the title and the
  first customer message, and returns ID and link of the similar
  tickets; the model opens the relevant ones. Without Context Chat it
  returns an empty list with a reason. The instance ID it matches is
  pinned by a test vector shared with integration_zammad.
- add_zammad_internal_note is GROUP radius and irreversible, so the
  user confirms every note with the default thresholds. Ticket title
  and number come first, as the confirmation shows the first three
  arguments. The server checks the number, not the title. Notes are
  plain text. The tool is only offered when the ticket API is at
  version 2, which has the notes route.

The notes route stores a note as given, so marking the Assistant's
notes is the tool's job: every note ends with an empty line, a line
"---" and "Nextcloud Assistant for <display name>", and a footer the
model wrote itself is dropped. Before writing, the tool reads the
ticket and refuses a second note when an earlier Assistant note is
newer than the customer's last message, unless the user asked for
another one. An Assistant note is an internal note of type note by an
agent whose last two non-empty lines are that footer block; a customer
quoting it, the phrase inside a note, a public article and a footer
without the "---" line do not count.

The tools are offered whenever integration_zammad is installed. Whether
the user is connected cannot be seen without a request per run, so
users who are not get a not_connected answer with how to connect. The
classification test's fake app now holds real values for capabilities
a module compares, ticket_api 2 for Zammad.

Assisted-by: ClaudeCode:claude-opus-5-5
Signed-off-by: Christian Fu Mueller <christian-fu.mueller@nextcloud.com>
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.

1 participant