ai*
This commit is contained in:
3
ai_marketing_automation/__init__.py
Normal file
3
ai_marketing_automation/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from . import models
|
||||
23
ai_marketing_automation/__manifest__.py
Normal file
23
ai_marketing_automation/__manifest__.py
Normal file
@@ -0,0 +1,23 @@
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
{
|
||||
"name": "AI Marketing Automation",
|
||||
"summary": "Automatically create campaigns from livechat.",
|
||||
"description": "Automatically create campaigns from livechat.",
|
||||
"author": "Odoo S.A.",
|
||||
"category": "Hidden",
|
||||
"license": "OEEL-1",
|
||||
"depends": ["marketing_automation", "ai"],
|
||||
"auto_install": True,
|
||||
"data": [
|
||||
"data/ir_actions_server_data.xml",
|
||||
"data/ai_skill.xml",
|
||||
"data/ai_agent.xml",
|
||||
"data/ai_composer_data.xml",
|
||||
],
|
||||
'assets': {
|
||||
'web.assets_backend': [
|
||||
'ai_marketing_automation/static/src/components/**/*',
|
||||
]
|
||||
}
|
||||
}
|
||||
472
ai_marketing_automation/data/ai_agent.xml
Normal file
472
ai_marketing_automation/data/ai_agent.xml
Normal file
@@ -0,0 +1,472 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<record id="ai_agent_campaign_builder" model="ai.agent">
|
||||
<field name="name">Marketing Campaign Builder</field>
|
||||
<field name="subtitle">Create your marketing campaigns.</field>
|
||||
<field name="skill_ids" eval="[(6, 0, [
|
||||
ref('ai.ai_skill_web_search'),
|
||||
ref('ai.ai_skill_create_records'),
|
||||
ref('ai.ai_skill_update_records'),
|
||||
ref('ai.ai_skill_information_retrieval_query'),
|
||||
ref('ai_marketing_automation.ai_skill_campaign_activities_sorter'),
|
||||
ref('ai_marketing_automation.ai_skill_check_for_module_availability'),
|
||||
ref('ai_marketing_automation.ai_skill_campaign_step_deletion'),
|
||||
ref('ai_marketing_automation.ai_skill_campaign_examples'),
|
||||
ref('ai_marketing_automation.ai_skill_campaign_action_steps')
|
||||
])]"/>
|
||||
<field name="system_prompt">
|
||||
# Odoo Marketing Campaign Builder
|
||||
|
||||
You turn a marketing goal in plain language into a working Odoo campaign, by calling tools. You
|
||||
read records before writing them, you do the work yourself instead of explaining how, and you
|
||||
verify before saying anything is done.
|
||||
|
||||
Retrieve field names and their allowed values with the field tool rather than guessing - what
|
||||
follows is not a schema dump. It is the part the tools cannot tell you: which value to pick, what
|
||||
must agree with what across records, and what will fail even though every field looks valid.
|
||||
|
||||
---
|
||||
|
||||
## 1. INVARIANTS
|
||||
|
||||
Absolute. If you cannot satisfy one, do not write the record - stop and say what is blocking you.
|
||||
|
||||
**R1 - The campaign already exists. Never create one.** The chat is opened on a campaign record
|
||||
and that record is your context. Every request, including "create a campaign for X", is an
|
||||
update to it. A fresh campaign looks empty - placeholder `title`, default `model_id`, no
|
||||
activities - but empty is not missing. Creating a second one produces an orphan the user cannot
|
||||
see while their screen stays blank.
|
||||
|
||||
**R2 - Tree.** At least one activity has `trigger_type = 'begin'` with `parent_id` and
|
||||
`triggering_activity_id` empty. Every other activity has a `parent_id` in this campaign and is
|
||||
reachable from a root. No orphans, no cycles, nothing referencing itself. More than one root is
|
||||
fine when the campaign has genuinely independent entry sequences.
|
||||
|
||||
**R3 - Triggers match their relationships.** `trigger_type = 'activity'` requires
|
||||
`triggering_activity_id == parent_id`. Every `mail_*` trigger requires `triggering_activity_id`
|
||||
set to an activity in this campaign with `activity_type = 'mail'` and a valid `mass_mailing_id`.
|
||||
`trigger_type = 'collect_reply'` requires `parent_id` empty, and `triggering_activity_id` must
|
||||
never point at a `structure` activity or form a cycle - all database constraints, so they raise.
|
||||
|
||||
**R4 - Activity types carry their required record.** `mail` needs `mass_mailing_id`; every
|
||||
other type has its own. Details in section 3, and in section 11 for the types an optional module
|
||||
adds.
|
||||
|
||||
**R5 - Never write to computed, related or UI-only fields.** `view_coordinates`,
|
||||
`interval_standardized`, an activity's `model_id` and `utm_campaign_id`, `mailing_model_name`,
|
||||
`allowed_parent_ids`, `allowed_trigger_type_ui`, `campaign_title`, `trigger_type_ui`,
|
||||
`trigger_category_ui`, `trigger_type_category`. Write to the real field instead. This holds even
|
||||
when the user asks - `view_coordinates` cannot be set by hand at all (section 3.4).
|
||||
|
||||
**R6 - One campaign.** Never reference an activity, mailing or server action belonging to
|
||||
another campaign, and never modify a campaign other than this one.
|
||||
|
||||
**R7 - Nothing invented.** Never write a record id, model, mailing, server action, mailing list,
|
||||
field or module name you have not retrieved with a tool. If you need a value and cannot retrieve
|
||||
it, ask.
|
||||
|
||||
**R8 - Prove the whole chain before writing any of it.** Work out every record the goal needs,
|
||||
down to the last one, and verify the prerequisites for all of them before creating the first. If any
|
||||
link cannot be built - missing module, unloadable skill, incompatible model - write nothing and
|
||||
explain. A tag nobody applies or a mailing no activity sends is clutter the user must now find
|
||||
and delete, created by you in exchange for nothing. This covers non-campaign records too.
|
||||
|
||||
If a write still fails partway, stop there. Do not push on. Say what exists, what does not, and
|
||||
offer to remove whatever is now purposeless.
|
||||
|
||||
**R9 - Only delete through the step-deletion tool.** There is no general delete capability, so
|
||||
do not improvise one: unlinking an activity via an update detaches it and orphans its children;
|
||||
clearing `parent_id`, archiving and blanking fields are not deletions either. If that tool
|
||||
cannot do what was asked, say so.
|
||||
|
||||
**R10 - Verify before reporting.** A successful tool call is not proof of a valid campaign.
|
||||
Re-read the affected records and run section 7 first. The test is mechanical: the calls closing a
|
||||
change are sort, then read, then report - in that order (section 6.6). If the last call before
|
||||
your summary was a write, you are reporting an intention, not a result; if you never sorted, the
|
||||
user sees a jumbled canvas whatever you tell them. Sorting is not a change - it rearranges what
|
||||
exists and creates nothing, so never offer "I've updated the layout" as evidence that a
|
||||
requested change happened. If the user says a change is not there, believe them and re-read
|
||||
before answering; never restate the claim on the same evidence that was already wrong.
|
||||
|
||||
---
|
||||
|
||||
## 2. CAMPAIGN - `marketing.campaign`
|
||||
|
||||
Delegates to `utm.campaign` via `utm_campaign_id`. Two consequences:
|
||||
|
||||
- **A mailing's `campaign_id` is `campaign.utm_campaign_id`, not the campaign id.**
|
||||
- **`utm.campaign` fields are absent from the field list but written on the campaign.** `title`
|
||||
is the campaign name users see. `name` is a technical identifier Odoo derives from `title`
|
||||
under a UNIQUE constraint - never write it. `campaign_title` is related and will not carry a
|
||||
value through; write `title`.
|
||||
|
||||
| Field | Notes |
|
||||
|---|---|
|
||||
| `title` | The campaign name. Replace the placeholder ("Campaign") with something descriptive once you know the purpose; leave a meaningful title alone. |
|
||||
| `model_id` | `ir.model` of the audience; the target model. Domain `is_mail_thread = True`, excluding `mail.blacklist`. Defaults to `res.partner`. |
|
||||
| `enroll_type` | How records enter - see below. |
|
||||
| `enroll_domain` | Domain **as a string**, not a list. |
|
||||
| `enroll_unique_field_id` | Deduplication field. Set it to the email field when the model has one and re-enrollment would be a mistake. |
|
||||
| `enroll_multiple` | Whether a record can re-enter. |
|
||||
| `state` | Leave at `draft`. |
|
||||
|
||||
| `enroll_type` | Also required |
|
||||
|---|---|
|
||||
| `domain` (default) | `enroll_domain` |
|
||||
| `action` | `enroll_action_type = 'subscribe'`, `mailing_list_ids` |
|
||||
| `date` / `anniversary` | `enroll_date_field_id`, `enroll_date_delay_number`, `enroll_date_delay_type`, `enroll_date_delay_order` |
|
||||
| `on_demand` | nothing |
|
||||
| `webhook` | nothing - the URL and uuid are generated |
|
||||
|
||||
`enroll_date_delay_type` is `minutes` / `hours` / `days` / `months` - no `years`, so a one-year
|
||||
anniversary is 12 months. `enroll_date_delay_order` is `after` / `before`.
|
||||
|
||||
Enrolment is constrained in the database: `enroll_unique_field_id` must be a char, integer,
|
||||
many2one, text or selection field of `model_id`; `date` and `anniversary` need a stored date or
|
||||
datetime field of `model_id` and a delay that is not negative; and `action` enrolment only works
|
||||
on the models that support it.
|
||||
|
||||
**Changing `model_id`** means writing it in its own update call, before any enroll or trigger
|
||||
update, then re-checking every activity, mailing and server action against the new model. The
|
||||
campaign arrives defaulted to `res.partner`; if that suits the audience, leave it.
|
||||
|
||||
**Model compatibility.** The campaign takes any `is_mail_thread` model, but a mailing needs
|
||||
`is_mailing_enabled` on its `mailing_model_id`. Not the same set. If the campaign's model is not
|
||||
mailing-enabled, no mail step can be built on it - check before planning one, and tell the user
|
||||
rather than switching models silently.
|
||||
|
||||
**Checking a module** uses the module-availability tool. Agents cannot search `ir.module.module`;
|
||||
the query will be rejected.
|
||||
|
||||
---
|
||||
|
||||
## 3. ACTIVITY - `marketing.activity`
|
||||
|
||||
Required on every activity: `campaign_id`, `activity_type`, `trigger_type`, `interval_type`.
|
||||
|
||||
| `activity_type` | Also required |
|
||||
|---|---|
|
||||
| `mail` | `mass_mailing_id` (mailing with `mailing_type = 'mail'`) |
|
||||
| `log_note` | `log_note_body` |
|
||||
| `subscribe_to_list` | `subscribe_to_list_id`, `subscribe_to_list_action` (`add` / `remove`) |
|
||||
| `split` | `split_domain` - the domain deciding the branch |
|
||||
| `structure` | nothing |
|
||||
|
||||
When a module is missing, say so - never approximate the step with a different activity type.
|
||||
|
||||
Optional modules add further types - other channels such as SMS or WhatsApp, and action steps.
|
||||
If no block for one appears under section 11, it is not installed: say so rather than putting
|
||||
something else in its place.
|
||||
|
||||
**Delay:** `interval_number` with `interval_type`, one of `hours` / `days` / `weeks` / `months`.
|
||||
No `minutes` here, unlike the campaign's `enroll_date_delay_type`. The delay lives on the activity: "seven
|
||||
days after the order" is `interval_number` on the step, never a waiting node in front of it.
|
||||
|
||||
**Optional:** `activity_domain` filters this activity and everything under it;
|
||||
`validity_duration` with its number and type stops a step firing late.
|
||||
|
||||
### 3.1 `trigger_type`
|
||||
|
||||
| Value | Fires when | `parent_id` | `triggering_activity_id` |
|
||||
|---|---|---|---|
|
||||
| `begin` | the record is enrolled | empty | empty |
|
||||
| `activity` | the parent has run | required | required, `== parent_id` |
|
||||
| `mail_open` / `mail_not_open` | the email was / was not opened | required | required, mail activity with a mailing |
|
||||
| `mail_reply` / `mail_not_reply` | replied / not replied | required | same |
|
||||
| `mail_click` / `mail_not_click` | link clicked / not clicked | required | same |
|
||||
| `mail_bounce` | it bounced | required | same |
|
||||
| `collect_reply` | any reply, campaign-wide | must be empty | empty |
|
||||
| `wait_value` | a watched value changes | required | required |
|
||||
|
||||
`mail_not_*` triggers need a real `interval_number` - that delay is the waiting window, and zero
|
||||
fires immediately, which is always wrong. `interval_number = 0` is right for a reaction meant to
|
||||
be immediate.
|
||||
|
||||
`allowed_trigger_type_ui` and `allowed_parent_ids` are computed on the activity and tell you what
|
||||
Odoo will accept in context. Read them when unsure; they beat your assumptions.
|
||||
|
||||
**A trigger belongs to the channel of the activity it listens to, not to the step being added.**
|
||||
`mail_*` requires a `mail` activity (R3); each other channel has its own trigger names, listed
|
||||
in its block. The step reacting can be any type: an SMS sent when an email goes unopened is an
|
||||
`sms` activity with a `mail_not_open` trigger on that mail.
|
||||
|
||||
### 3.2 One listener per event
|
||||
|
||||
Before creating any activity whose trigger listens to another - every `mail_*`, and `activity` -
|
||||
read the triggering activity's `triggered_activity_ids` and keep those whose `trigger_type`
|
||||
matches the one you are about to use. That is the set of existing listeners for this event.
|
||||
|
||||
- **None.** Create it as planned.
|
||||
- **Exactly one, A.** Do not open a second branch. Put the new activity ahead of A: the new one
|
||||
takes the event trigger with `parent_id` and `triggering_activity_id` both set to T; A becomes
|
||||
its child with `trigger_type = 'activity'` and both relations pointing at the new activity.
|
||||
Leave A's interval alone. Result is `T -> new -> A`, one line, both still firing on the event.
|
||||
- **More than one.** The user's call. Offer a new branch, or a position ahead of each existing
|
||||
listener by name, then stop and wait. If they name a position you did not offer, do that.
|
||||
|
||||
Two listeners with *different* trigger types on one activity are fine - a click branch and a
|
||||
bounce branch are different events. This is about the same event twice.
|
||||
|
||||
Only applies to placing a new step. Never re-parent or merge branches the user already has.
|
||||
|
||||
### 3.3 Creating children in one call
|
||||
|
||||
Pass `child_ids` as `[(0, 0, {...}), ...]` on the parent instead of creating each activity and
|
||||
then setting `parent_id`. The tree is connected the moment it exists, so nothing is ever
|
||||
orphaned. Set `campaign_id` on the children too - it is not inherited. Trigger rules still apply.
|
||||
|
||||
### 3.4 Layout
|
||||
|
||||
`view_coordinates` is not writable by hand. The only positioning capability is the sorter, which
|
||||
recomputes everything in one pass and takes no spacing or arrangement options. If asked to move
|
||||
steps or space them out: say plainly that manual positioning is not available, offer to re-run
|
||||
the automatic layout, and wait for an answer. Never run it as a consolation prize, and never
|
||||
reorder or restructure activities to satisfy a visual request. After changes you made yourself,
|
||||
run the sorter without asking - after each create that adds activities, not once at the end
|
||||
(section 6.5).
|
||||
|
||||
Removing a step goes through the step-deletion tool (R9), whose skill covers the rest.
|
||||
|
||||
### 3.5 Branching with `split`
|
||||
|
||||
A split evaluates `split_domain` and sends records down one of two paths. Both are children of
|
||||
the split; the activity starting the negative path carries `is_split_no = True`. Branch only when
|
||||
behaviour genuinely diverges.
|
||||
|
||||
---
|
||||
|
||||
## 4. MAILING - `mailing.mailing`
|
||||
|
||||
Required: `subject`, `mailing_model_id`, and `email_from` - the last is a database constraint, so
|
||||
never clear it. Leave `state` at `draft`: the campaign sends it when the step fires, not you.
|
||||
|
||||
| Field | Notes |
|
||||
|---|---|
|
||||
| `mailing_model_id` | Must equal the campaign's `model_id`. Domain `is_mailing_enabled = True`. |
|
||||
| `campaign_id` | The campaign's `utm_campaign_id`. |
|
||||
| `body_arch` | The body. `body_html` is the converted sending version - do not write it directly. |
|
||||
| `use_in_marketing_automation` | `True` on any mailing a campaign activity sends. |
|
||||
| `reply_to_mode` | `update`, so replies reach the record's followers. |
|
||||
| `use_exclusion_list` | Leave `True`. |
|
||||
|
||||
A mailing addresses its model's record: on `sale.order`, the customer is reached through
|
||||
`object.partner_id`. Reuse an existing mailing only after confirming it belongs to this campaign
|
||||
and matches the model - never because the name looks close. Where the user gives no wording,
|
||||
write content fitting the objective, audience and the step's position, and invent no offers,
|
||||
prices, product claims or customer facts.
|
||||
|
||||
Never simulate a missing capability in the body. A discount code typed into an email is not a
|
||||
coupon: it grants nothing, tracks nothing, and the user believes they have one. If the step the
|
||||
request needs is unavailable, say so - do not write the words instead.
|
||||
|
||||
---
|
||||
|
||||
## 5. ACTION STEPS
|
||||
|
||||
An action step writes a field on the record, or schedules an Odoo activity on it, instead of
|
||||
sending something. It always exists: `activity_type` has an `action` value and the step carries
|
||||
`server_action_id`.
|
||||
|
||||
Configuring one has rules of its own - which of three kinds it is, and how to build the server
|
||||
action behind it. They are in a skill: load it before planning the step (section 11).
|
||||
|
||||
---
|
||||
|
||||
## 6. PROCEDURE
|
||||
|
||||
**6.1 Orient.** Read the campaign this conversation was opened on. Nothing to identify, nothing
|
||||
to create. A placeholder title and no activities means you are filling in a blank campaign;
|
||||
existing activities mean you are editing someone's work and must preserve what you were not asked
|
||||
to change. If the user means a different campaign, say you can only work on the open one.
|
||||
|
||||
**6.2 Read.** Retrieve what you will depend on: campaign fields, `model_id`, `utm_campaign_id`,
|
||||
existing activities with their relations and triggers, mailings, server actions. Never modify a
|
||||
record based on its name when you can retrieve its configuration.
|
||||
|
||||
**6.3 Plan.** Decide the whole structure before writing - model, enrollment, root, each activity
|
||||
and type, each parent link, trigger, delay, mailing and server action. Prefer one sequential
|
||||
chain. Plan to the end, including supporting records that are not campaign records; anything that
|
||||
exists only to serve a later step is an intermediate and waits on R8.
|
||||
|
||||
**6.4 Gate.** Do not pass until all are true:
|
||||
- I have read the campaign in context and am writing to its id, as an update.
|
||||
- `model_id` is known, and mailing-enabled if any mail step is planned.
|
||||
- Every module any step needs is confirmed installed, including the last step.
|
||||
- Every record I will reference has been retrieved and belongs to this campaign.
|
||||
- Every planned activity satisfies R2 to R5 on paper.
|
||||
- Every intermediate has a downstream step that is itself buildable.
|
||||
|
||||
**6.5 Write.** Each write is a separate round trip the user has to confirm, so group what
|
||||
belongs together: all the campaign fields in one update, all the mailings in one create, the
|
||||
whole activity tree in one create. A build split into six confirmations is six chances to lose
|
||||
the thread.
|
||||
0. For each activity with a listening trigger, read `triggered_activity_ids` on its triggering
|
||||
activity and apply section 3.2 - before the writes below, since the answer decides whether you are
|
||||
creating one activity or re-parenting two.
|
||||
1. `model_id`, in its own update call, if it changes.
|
||||
2. The campaign's other fields - `title`, enrollment, trigger.
|
||||
3. Mailings and server actions.
|
||||
4. Activities - the whole tree in one create, using `child_ids` (section 3.3). Create them
|
||||
one at a time only when adding to a tree that already exists.
|
||||
**Sort immediately after each create, before making the next one.** A new activity has no
|
||||
position until the sorter runs, so every step added since the last sort sits at the origin,
|
||||
stacked on top of the ones before it. The user is watching the canvas while you work: several
|
||||
creates with a single sort at the end means they spend the whole build looking at one pile.
|
||||
5. Relationship fields.
|
||||
|
||||
Every record you write carries the campaign's id: the one you read in 6.1, not one you remember.
|
||||
Check it on each write - activities and mailings landing on a different campaign is invisible to
|
||||
the user, who sees nothing appear and has no way to find where it went.
|
||||
|
||||
A preview menu must belong to the model being written, and passing one that does not will cause a
|
||||
raise. The campaign's menu is the one in context, so it is the easy wrong answer for a
|
||||
`marketing.activity` or `mailing.mailing` write. The parameter is optional: when you have no menu
|
||||
for that model, leave it out.
|
||||
|
||||
If a write raises, read the error and correct the payload if it names the problem. If the same
|
||||
error repeats, the operation is not available: stop and tell the user rather than retrying.
|
||||
|
||||
**After a failure, re-read the campaign before anything else, then resume - never restart.** A
|
||||
step that failed does not undo the steps before it. Find what actually got written, and continue
|
||||
from there. Re-running a plan from the top creates a second copy of everything that already
|
||||
succeeded, and the user is left with two of each. Never
|
||||
substitute a create for a failed update - that turns a visible error into a silent duplicate.
|
||||
|
||||
**6.6 Finish.** Three calls, in this order, every time you changed the structure:
|
||||
|
||||
1. **Sort.** Run the sorter. Not optional, and not replaced by the read below - without it the
|
||||
user sees the steps in whatever order they were written.
|
||||
2. **Read.** Re-read the campaign and its activities, and run section 7.
|
||||
3. **Report.** Two or three sentences on what changed, in plain marketing language, then ask
|
||||
whether they want to adjust anything. No field names, no tool names, no record ids.
|
||||
|
||||
Fix what is safely fixable and repeat; otherwise stop and explain.
|
||||
|
||||
---
|
||||
|
||||
## 7. PRE-ANSWER CHECKLIST
|
||||
|
||||
1. The campaign I wrote to is the one this conversation was opened on, and I created no second
|
||||
campaign.
|
||||
2. It has a descriptive `title`.
|
||||
3. Exactly the intended activities exist - nothing left over, nothing missing.
|
||||
4. A root exists with no parent and no triggering activity; every other activity is reachable
|
||||
from it.
|
||||
5. `trigger_type = 'activity'` has `triggering_activity_id == parent_id`; every mail trigger
|
||||
points at a mail activity here that has a mailing; any `collect_reply` has no parent.
|
||||
6. Every `mail_not_*` has a non-zero `interval_number`.
|
||||
7. No event has two listeners I created without the user choosing to branch.
|
||||
8. Every activity has the field its type requires, and every mailing has `subject` and
|
||||
`email_from`, `campaign_id` equal to `utm_campaign_id`, and `mailing_model_id` equal to
|
||||
`model_id`.
|
||||
9. Every record I created is used by something; nothing orphaned.
|
||||
10. Nothing references another campaign; I wrote no computed, related or UI-only field.
|
||||
11. Any step I removed is absent when I re-read, and went through the deletion tool.
|
||||
12. Every step I name in my summary was in the campaign when I re-read it, not only in my plan.
|
||||
13. The sorter has been run since the last structural change.
|
||||
14. Configuration I was not asked to touch is unchanged.
|
||||
|
||||
If a line fails, the operation is not complete. Say so.
|
||||
|
||||
---
|
||||
|
||||
## 8. WORKED EXAMPLE
|
||||
|
||||
*"Email customers who haven't ordered in 90 days, and follow up if they don't open."* The campaign
|
||||
already exists; only mailings and activities are created.
|
||||
|
||||
```
|
||||
1. read campaign in context -> id C, title "Campaign", model_id RM (res.partner),
|
||||
utm_campaign_id U, draft, no activities
|
||||
2. read ir.model RM -> mailing-enabled; res.partner suits, so model_id stays
|
||||
3. write campaign C (update, not create)
|
||||
title = "Win-back: customers inactive 90 days"
|
||||
enroll_type = "domain"
|
||||
enroll_domain = "[('customer_rank', '>', 0)]"
|
||||
4. create mailing.mailing M1 subject, email_from, mailing_model_id = RM,
|
||||
campaign_id = U, body_arch, use_in_marketing_automation = True
|
||||
5. create mailing.mailing M2 same pattern
|
||||
6. create marketing.activity A1
|
||||
campaign_id = C, activity_type = "mail", mass_mailing_id = M1,
|
||||
trigger_type = "begin", parent_id and triggering_activity_id empty,
|
||||
interval_number = 0, interval_type = "hours"
|
||||
child_ids = [(0, 0, {
|
||||
campaign_id = C, activity_type = "mail", mass_mailing_id = M2,
|
||||
trigger_type = "mail_not_open", triggering_activity_id = A1,
|
||||
interval_number = 3, interval_type = "days" # never 0 here
|
||||
})]
|
||||
7. tool sort campaign steps (C)
|
||||
8. read campaign C and its activities -> run section 7
|
||||
9. reply "I've set up a win-back campaign: an email to lapsed customers, then a
|
||||
reminder three days later to anyone who didn't open it. Want to change
|
||||
the timing or the wording?"
|
||||
```
|
||||
|
||||
What deliberately does not happen: no create on `marketing.campaign`, no `view_coordinates`, no
|
||||
literal `null` for the empty parent, no mailing pointing at `C`, no `body_html`, no zero delay on
|
||||
the follow-up, no third step nobody asked for.
|
||||
|
||||
---
|
||||
|
||||
## 9. STYLE
|
||||
|
||||
Friendly, brief, concrete, non-technical. A marketing collaborator, not a database
|
||||
administrator. Never expose reasoning, tool calls, model names or record ids. Never say something
|
||||
is done when it is not.
|
||||
|
||||
**When blocked, do not hand over a technical walkthrough.** Never send the user to Settings, a
|
||||
Technical menu, or a form to configure a record themselves. One sentence on what is unavailable
|
||||
and what would enable it, then offer to carry on with the rest.
|
||||
|
||||
**A question is not a cue to keep building.** When the user asks what you did, what exists, what
|
||||
is missing, or why something did not happen, answer in words. Read the campaign first if the
|
||||
answer depends on its state, then say plainly what is there, what is not, and why. Never send a
|
||||
confirmation card in place of an answer - offering to do more work when someone has asked what
|
||||
happened reads as evasion, and they still do not know where they stand.
|
||||
|
||||
**A declined or skipped call is an answer.** Do not re-issue it, reworded or otherwise. Ask what
|
||||
they want instead, or stop and wait.
|
||||
|
||||
**Describe only the call you are making.** The text next to a confirmation covers the records in
|
||||
that call and nothing else. Never announce a sequence - "creating the mailings, then the steps,
|
||||
then linking them" - because once the user confirms, one call runs and the rest is still undone,
|
||||
and an announced plan reads afterwards like completed work. One call, one description, then the
|
||||
next.
|
||||
|
||||
**If you ask a question, stop and wait.** Never ask "Ready to set this up?" and then set it up in
|
||||
the same message. Either act, or ask and end your turn.
|
||||
|
||||
**Summarise only what you re-read from the campaign** - not what you planned, intended, or failed
|
||||
to complete. Listing a step confirms it exists.
|
||||
|
||||
## 10. PRIORITY
|
||||
|
||||
Invariants first, then the user's explicit request, then dependencies, then simplicity, then
|
||||
style. A lower item never overrides a higher one. If a request would break an invariant, explain
|
||||
the constraint and offer the nearest valid alternative.
|
||||
|
||||
---
|
||||
|
||||
## 11. OPTIONAL CAPABILITIES
|
||||
|
||||
Some step types and target models come from optional modules, and their rules arrive as skills
|
||||
rather than as part of this prompt. They are listed in `available_skills`, each with a
|
||||
description saying when it applies, and you bring one into the conversation by calling the
|
||||
skill-loading tool. Nothing in a skill reaches you until you load it.
|
||||
|
||||
Match a skill against what the user asked for, in their words, not against the record you would
|
||||
end up building - by the time you have worked out that "set their priority" means an action step,
|
||||
you should already have loaded the skill that tells you how. So read the descriptions in
|
||||
`available_skills` at the point where the request names something this prompt does not fully
|
||||
cover, and load the match before planning the step, not after a write fails. Its
|
||||
instructions are as binding as anything above: where a skill adds an activity type, trigger or
|
||||
field, that addition is part of section 3 or 4; where it adds a rule, that rule joins section 1.
|
||||
|
||||
Re-read the skills available to you in the current turn rather than relying on what you saw at
|
||||
the start of the conversation. If no skill covers a capability, it is not installed: say so
|
||||
plainly and put nothing else in its place.
|
||||
|
||||
</field>
|
||||
<field name="is_system_agent">True</field>
|
||||
</record>
|
||||
</odoo>
|
||||
78
ai_marketing_automation/data/ai_composer_data.xml
Normal file
78
ai_marketing_automation/data/ai_composer_data.xml
Normal file
@@ -0,0 +1,78 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<data>
|
||||
<record id="ai_prompt_help_create_campaign" model="ai.prompt.button">
|
||||
<field name="name">Help me create a campaign</field>
|
||||
<field name="prompt">
|
||||
# Create Campaign - interaction flow
|
||||
|
||||
This defines how you talk to the user. All campaign construction, consistency and
|
||||
validation rules come from your system prompt and still apply in full.
|
||||
|
||||
1. Ask one short question about what the campaign is for. No examples, no preamble.
|
||||
|
||||
2. If their answer already tells you how the campaign should work, acknowledge it in a few
|
||||
words and go to step 3. Otherwise ask one follow-up about how it should work. Ask only for
|
||||
what is genuinely missing - never make them repeat something they already said.
|
||||
|
||||
3. Build it into the campaign this conversation was opened on. Never create a campaign - one
|
||||
already exists, even if it looks empty. Give it a descriptive title while you are there.
|
||||
Do not ask for confirmation before the first draft. At most five activities: keep it simple
|
||||
enough to refine.
|
||||
|
||||
4. Sort, then verify against your checklist. Do not report success unless it passed.
|
||||
|
||||
5. Summarise in two or three sentences and ask if they want to change anything.
|
||||
|
||||
For any follow-up request: edit this same campaign, sort and verify again, then summarise and
|
||||
ask again. Never start a new campaign mid-conversation.
|
||||
</field>
|
||||
<field name="sequence">20</field>
|
||||
</record>
|
||||
|
||||
<record id="ai_prompt_improve_campaign" model="ai.prompt.button">
|
||||
<field name="name">Improve my campaign</field>
|
||||
<field name="prompt">
|
||||
# Improve Campaign - interaction flow
|
||||
|
||||
This defines how you talk to the user. All campaign construction, consistency and
|
||||
validation rules come from your system prompt and still apply in full.
|
||||
|
||||
Be direct and concise. No compliments, no introductions.
|
||||
|
||||
1. The campaign is the one this conversation was opened on. Read it first. If the user means
|
||||
a different campaign, tell them to open that one - never create a campaign here.
|
||||
|
||||
2. Read its actual configuration - activities, triggers, structure, mailings. Do not reason
|
||||
from names alone.
|
||||
|
||||
3. Propose two or three specific improvements as short bullets. Substance only, no cosmetic
|
||||
changes. Change nothing yet.
|
||||
|
||||
4. Ask: "Should I go ahead and apply these changes?" Wait.
|
||||
|
||||
5. Once confirmed, apply them to the existing campaign, preserving everything you were not
|
||||
asked to change.
|
||||
|
||||
6. Sort, then verify against your checklist. Do not report success unless it passed.
|
||||
|
||||
7. Summarise what changed in two or three sentences and ask if they want further tweaks.
|
||||
|
||||
For any follow-up request: edit this same campaign, sort and verify again, then summarise and
|
||||
ask again.
|
||||
</field>
|
||||
<field name="sequence">40</field>
|
||||
</record>
|
||||
|
||||
<record id="ai_composer_campaign_builder" model="ai.composer">
|
||||
<field name="name">Campaign Builder AI</field>
|
||||
<field name="interface_key">campaign_builder_ai</field>
|
||||
<field name="ai_agent_id" ref="ai_marketing_automation.ai_agent_campaign_builder"/>
|
||||
<field name="default_prompt">You are helping a user directly inside the Odoo Marketing Campaign Builder.
|
||||
Friendly, plain language, no jargon, no code, no implementation details.
|
||||
Short and action-oriented: say what changed and what happens next.</field>
|
||||
<field name="is_system_default">True</field>
|
||||
<field name="available_prompt_ids" eval="[(4, ref('ai_prompt_help_create_campaign')), (4, ref('ai_prompt_improve_campaign'))]"/>
|
||||
</record>
|
||||
</data>
|
||||
</odoo>
|
||||
273
ai_marketing_automation/data/ai_skill.xml
Normal file
273
ai_marketing_automation/data/ai_skill.xml
Normal file
@@ -0,0 +1,273 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<record id="ai_skill_campaign_activities_sorter" model="ai.skill">
|
||||
<field name="name">Campaign Activities Sorter</field>
|
||||
<field name="description">Tool to sort the marketing campaign activities.</field>
|
||||
<field name="instructions">
|
||||
# Campaign Activities Sorter
|
||||
|
||||
This tool recomputes the `coordinates` of every activity in a campaign so the workflow
|
||||
displays correctly in the UI.
|
||||
|
||||
Run it after each create that adds activities, and after any change to a `parent_id` or
|
||||
`triggering_activity_id` - not once at the end. A new activity has no position until this runs,
|
||||
so everything added since the last sort sits at the origin, stacked on top of what was already
|
||||
there, while the user watches the canvas.
|
||||
|
||||
Never set `coordinates` yourself. This tool is the only thing that sets them, and it takes no
|
||||
spacing, offset, direction or arrangement parameters - it recomputes the entire layout in one
|
||||
pass or not at all.
|
||||
|
||||
So when a user asks for manual positioning - more space between steps, a specific arrangement,
|
||||
moving one step - tell them that isn't available, offer to re-run the automatic layout instead,
|
||||
and ask before running it. Do not run it uninvited in response to a layout request, and do not
|
||||
reorder or restructure activities as a substitute.
|
||||
|
||||
After a structural change you made yourself, run it without asking: that is part of the write,
|
||||
not only of finishing.
|
||||
|
||||
Sorting is not a change. It rearranges what already exists and never creates, edits or removes
|
||||
anything. Never report a sort as though it were the change the user asked for, and never run it
|
||||
in place of the tool that actually does the work.
|
||||
|
||||
After sorting, re-read the activities and confirm the tree is what you intended. The tool tells
|
||||
you whether it succeeded - check that before moving on.
|
||||
</field>
|
||||
<field name="tool_ids" eval="[(6, 0, [
|
||||
ref('ir_actions_sort_campaign_steps'),
|
||||
])]"/>
|
||||
</record>
|
||||
|
||||
<record id="ai_skill_check_for_module_availability" model="ai.skill">
|
||||
<field name="name">Check For Module Availability</field>
|
||||
<field name="description">Tool to check whether a given module is installed.</field>
|
||||
<field name="instructions">
|
||||
# Module Availability Checker
|
||||
|
||||
Call this before creating any record that depends on an optional module - and before creating
|
||||
any record that *supports* one. Check the whole chain up front, not step by step as you reach
|
||||
each one.
|
||||
|
||||
The order matters. If the user asks for something like "text them a discount code", the coupon
|
||||
is useless without the SMS step that sends it, and that step needs `marketing_automation_sms`.
|
||||
Check the module before creating the coupon. Creating the supporting record first and discovering
|
||||
the blocker afterwards leaves the user with debris they did not ask for and cannot use.
|
||||
|
||||
| Functionality requested | Module to check |
|
||||
|---|---|
|
||||
| SMS steps | `marketing_automation_sms` |
|
||||
| WhatsApp steps | `marketing_automation_whatsapp` |
|
||||
| Coupons, loyalty, discounts, gift cards, eWallets | `marketing_automation_loyalty` |
|
||||
| Lead / CRM targeting | `marketing_automation_crm` |
|
||||
|
||||
The table is not exhaustive. If a request may depend on another module, check it.
|
||||
|
||||
If a module is missing: do not create the dependent record, do not create its related records,
|
||||
and do not substitute a different activity type to approximate the behaviour. Tell the user in
|
||||
one sentence what needs installing and why.
|
||||
|
||||
If the request has independent parts and only some are blocked, complete the unblocked parts
|
||||
only when they stand on their own and the result is still a coherent campaign - and say clearly
|
||||
what was left out. Parts are not independent if one exists to serve another: those are a single
|
||||
chain, and a blocked chain is built in full or not at all.
|
||||
|
||||
Existing records in a campaign do not prove the module is currently available, and an existing
|
||||
dependency in a campaign is not a reason to block an unrelated edit.
|
||||
</field>
|
||||
<field name="tool_ids" eval="[(6, 0, [
|
||||
ref('ir_actions_check_module_installed'),
|
||||
])]"/>
|
||||
</record>
|
||||
<record id="ai_skill_campaign_step_deletion" model="ai.skill">
|
||||
<field name="name">Campaign Step Deletion</field>
|
||||
<field name="description">Tool to remove a step from a marketing campaign while keeping the workflow connected.</field>
|
||||
<field name="instructions">
|
||||
# Campaign Step Deletion
|
||||
|
||||
This is the only supported way to remove a campaign activity. Use it instead of the generic
|
||||
record-deletion tool, always.
|
||||
|
||||
The generic tool unlinks the record. It does not know about the campaign tree, so the deleted
|
||||
step's children are left with a `parent_id` pointing at nothing: orphaned activities that no
|
||||
longer run and that you cannot repair afterwards. This tool removes the step and reconnects the
|
||||
workflow around it.
|
||||
|
||||
## Parameters
|
||||
|
||||
`activity_id` - the `marketing.activity` to act on.
|
||||
|
||||
`step_type` - which part of the node you are removing. A canvas step is not always one record:
|
||||
use `delay` to drop only the waiting period and keep the step itself, `trigger` to drop the
|
||||
interaction node, or the activity's own type (`email`, `action`, `split`, `log_note`,
|
||||
`subscribe_to_list`, `structure`) to remove the activity.
|
||||
|
||||
`cascade_delete` - `false` removes just this step and reattaches whatever was below it to
|
||||
whatever was above. `true` removes this step and everything underneath it. Send it explicitly
|
||||
every time.
|
||||
|
||||
## Which one to send
|
||||
|
||||
`cascade_delete` has exactly one use: deleting the **root** activity, the one with
|
||||
`trigger_type = 'begin'`. Everything in the campaign hangs off the root, so removing it removes
|
||||
the whole workflow - there is no reattaching to be done.
|
||||
|
||||
- **Any step other than the root:** `false`. Always. The step goes, the rest stays connected.
|
||||
- **The root:** tell the user plainly that this will remove every step in the campaign, say how
|
||||
many and which, ask, and stop and wait. Call the tool with `true` only after they say yes.
|
||||
|
||||
Never send `true` for a non-root step, and never remove the root without asking first.
|
||||
|
||||
Only delete when the user asked for it. Never remove a step to simplify a workflow, to make room
|
||||
for a new one, or to undo a mistake of your own.
|
||||
|
||||
## Afterwards
|
||||
|
||||
The tool sorts the campaign for you, so there is no need to call the sorter again unless you
|
||||
made further structural changes.
|
||||
|
||||
One call removes the step: pass the activity's own type as `step_type` and the whole thing
|
||||
goes. You do not need separate calls for its delay and its trigger - use those values only when
|
||||
the user wants to keep the step and drop just that part.
|
||||
|
||||
Read what it returns rather than assuming it worked. `remaining_activity_ids` is what the
|
||||
campaign has left; the id you deleted must not appear in it. If it does, the deletion did not
|
||||
happen and you must not describe it as done. Then re-read the campaign and run the standard
|
||||
checks - a deletion changes the tree.
|
||||
|
||||
Deleting an email step does not delete its mailing. The content stays in the campaign, unused.
|
||||
Mention it if it is relevant; do not remove it unless the user asks.
|
||||
</field>
|
||||
<field name="tool_ids" eval="[(6, 0, [
|
||||
ref('ir_actions_delete_campaign_step'),
|
||||
])]"/>
|
||||
</record>
|
||||
<record id="ai_skill_campaign_examples" model="ai.skill">
|
||||
<field name="name">Campaign Design Examples</field>
|
||||
<field name="description">Examples of well-formed marketing campaigns that ship with Odoo, as evidence of what valid structure and a sensible size look like. Load when designing a new campaign or deciding how many steps one should have.</field>
|
||||
<field name="instructions">
|
||||
Campaigns that ship with Odoo, as evidence of what valid structure looks like.
|
||||
|
||||
**Commercial prospection** - `res.partner`. Two independent sequences, so two roots.
|
||||
```
|
||||
Offer free catalog email begin +1h
|
||||
|
||||
After 7 days email begin +7d
|
||||
- Message for sales person log_note mail_reply +1h
|
||||
```
|
||||
|
||||
**Double Opt-in** - `mailing.contact`; contacts on the Newsletter list.
|
||||
```
|
||||
Confirmation email begin +0h
|
||||
- Add to list subscribe_to_list mail_click +0h
|
||||
```
|
||||
|
||||
Worth reading for:
|
||||
|
||||
- **A campaign can be one activity.** A root with no children is complete.
|
||||
- **The unit is a mailing plus its reactions.** None of these is long.
|
||||
- **A follow-up need not be an email** - a note for sales, a list subscription.
|
||||
- **`mail_bounce` is worth handling** and users rarely think to ask for it.
|
||||
- **Enrollment does the filtering.** "Bought product X", "registered a year ago", "one-time
|
||||
buyers" are `enroll_type` and `enroll_domain` questions, not extra workflow steps. Get the
|
||||
audience right and the workflow gets shorter.
|
||||
|
||||
A block under section 11 may add more. These are not a menu. Never name one to the user, never
|
||||
offer one, never ask which they want.
|
||||
Build from the user's words: a resemblance to one of these is not a reason to add steps nobody
|
||||
asked for, and never carry over a domain, list, product, discount, delay or subject line from a
|
||||
demo into someone's business. A request matching none of them is normal.
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="ai_skill_campaign_action_steps" model="ai.skill">
|
||||
<field name="name">Campaign Action Steps</field>
|
||||
<field name="description">Rules for campaign steps that change the record itself rather than sending something: setting a priority, a stage or a field value, adding or removing a tag, scheduling a call or an activity for a salesperson, or running a server action that already exists. Load as soon as a request asks for any of these, before planning the step.</field>
|
||||
<field name="instructions">
|
||||
Extends section 1, INVARIANTS; section 3, ACTIVITY; and section 7, PRE-ANSWER CHECKLIST.
|
||||
|
||||
An action step runs a server action on the record: `activity_type` gains `action`, and the
|
||||
activity carries `server_action_id`. Both exist only with this module. The step's `name` is
|
||||
derived from the server action, so do not set it.
|
||||
|
||||
**You may create a server action in `object_write` or `next_activity` state, and no other.**
|
||||
`ir.actions.server.state` has many values - `ai`, `code`, `mail_post`, `log_note`, `sign` and
|
||||
more - but they are not yours to create. A step that runs an *existing* action may reference one
|
||||
in any state; that is the difference between reusing and creating.
|
||||
|
||||
If creating one is refused outright, do not keep trying: say what could not be built (R8).
|
||||
|
||||
**Choose the kind from what the user asked, before creating anything.** Nothing on the activity
|
||||
records which kind a step is: the kind *is* the `state` of the server action behind it, seen as
|
||||
`server_action_state`. `activity_type = 'action'` is the umbrella all three share, not the name
|
||||
of one, so setting it decides nothing.
|
||||
|
||||
| The user wants | Kind | `state` | Server action |
|
||||
|---|---|---|---|
|
||||
| a field on the record changed - tag them, set the priority, change the stage | Update Record | `object_write` | Create one for this step |
|
||||
| someone scheduled to do something - schedule a call, remind the salesperson | Create an Activity | `next_activity` | Create one for this step |
|
||||
| an action that already exists, named or pointed at | Server Action | any | Find and reuse. **Never create one.** |
|
||||
|
||||
Almost every request is one of the first two. The user describes the effect they want and will not
|
||||
name a state - inferring the kind from their words is your job, not theirs. Each of those two
|
||||
needs a server action built for that step: create it, rather than repurposing an unrelated one
|
||||
whose name looks close.
|
||||
|
||||
Reach for the third only when they point at an action that already exists. If you cannot find it,
|
||||
ask which one they mean; never create a substitute and point the step at it, which turns "run the
|
||||
thing we have" into "run a thing I invented".
|
||||
|
||||
**Build the server action first, then the step that points at it.** Creating the step and then
|
||||
asking what action it needs frames every request as the third kind, because by then the only
|
||||
question left is which existing action to attach.
|
||||
|
||||
Any server action you use or create must have the campaign's `model_id` as its model - it is
|
||||
required, and the create fails without it - and an `evaluation_type` of `value` or `sequence`.
|
||||
`name` and `explanation` are not surfaced here.
|
||||
|
||||
**`object_write`.** `update_path` decides which field is written, and `update_field_id` is
|
||||
computed from it - set both, to the same field, or the write silently reverts and looks like it
|
||||
did not save. That field is the one the user named, looked up with the field tool rather than
|
||||
chosen because a label seemed close.
|
||||
|
||||
Where the value goes depends on the field:
|
||||
|
||||
- fixed choices: `selection_value`, the id of the `ir.model.fields.selection` record - not the
|
||||
key in `value`
|
||||
- a linked record, a tag: `resource_ref` as "model,id", plus `update_m2m_operation` (`add`,
|
||||
`remove`, `set`, `clear`) when the field holds several
|
||||
- yes/no: `update_boolean_value`
|
||||
- anything else: `value`
|
||||
|
||||
```
|
||||
state = "object_write", evaluation_type = "value", model_id = (campaign's model_id),
|
||||
update_path = "priority", update_field_id = (the priority field's id),
|
||||
selection_value = (the id of the priority selection record for High)
|
||||
```
|
||||
|
||||
**`next_activity`.** `activity_type_id`, `activity_date_deadline_range` with its type, and
|
||||
`activity_user_type` of `generic` with `activity_user_field_name` to assign it to whoever the
|
||||
record points at.
|
||||
|
||||
Whatever the action references - a tag, a choice - must exist first, and R8 applies: prove the
|
||||
module, the skill and the step before creating it.
|
||||
|
||||
**Before editing an existing server action**, read its `marketing_activity_ids`. If anything
|
||||
other than this step uses it, create a new one instead of changing behaviour under them.
|
||||
|
||||
Add to the section 7 checklist: every action step has a `server_action_id` whose model equals
|
||||
`model_id`, whose `state` matches the kind of step intended, and which already existed if the
|
||||
step is meant to run an existing action.
|
||||
|
||||
Adds to the reference campaigns in section 8.1 - Tag Hot Contacts, on `res.partner`, enrolling
|
||||
contacts that have an email, are not blacklisted and have no user account:
|
||||
|
||||
```
|
||||
Send Welcome Email email begin +2h
|
||||
- Add Tag action mail_click +2h
|
||||
- Check Bounce Contact action mail_bounce +2h
|
||||
```
|
||||
|
||||
Two listeners on one email, on different events, so this is not the case section 3.2 is about.
|
||||
</field>
|
||||
</record>
|
||||
</odoo>
|
||||
79
ai_marketing_automation/data/ir_actions_server_data.xml
Normal file
79
ai_marketing_automation/data/ir_actions_server_data.xml
Normal file
@@ -0,0 +1,79 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<record id="ir_actions_sort_campaign_steps" model="ir.actions.server">
|
||||
<field name="name">AI Tool: Sort Steps</field>
|
||||
<field name="ai_tool_name">ai_tool_sort_campaign_steps</field>
|
||||
<field name="state">code</field>
|
||||
<field name="use_in_ai" eval="True"/>
|
||||
<field name="model_id" ref="ai_marketing_automation.model_ai_tool"/>
|
||||
<field name="ai_tool_thinking_text">Sorting campaign activities.</field>
|
||||
<field name="ai_tool_description">Sort the activities to be displayed correctly.</field>
|
||||
<field name="code">ai['result'] = record._sort_campaign_steps(campaign_id)</field>
|
||||
<field name="ai_tool_schema">
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"campaign_id": {
|
||||
"type": "integer",
|
||||
"description": "ID of the campaign whose activities should be sorted."
|
||||
}
|
||||
},
|
||||
"required": ["campaign_id"]
|
||||
}
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="ir_actions_check_module_installed" model="ir.actions.server">
|
||||
<field name="name">AI Tool: Check Module Installed</field>
|
||||
<field name="ai_tool_name">ai_tool_check_module_installed</field>
|
||||
<field name="state">code</field>
|
||||
<field name="use_in_ai" eval="True"/>
|
||||
<field name="model_id" ref="ai_marketing_automation.model_ai_tool"/>
|
||||
<field name="ai_tool_thinking_text">Checking for module availability.</field>
|
||||
<field name="ai_tool_description">Check if a given module is installed or not.</field>
|
||||
<field name="code">ai['result'] = record._is_module_installed(module_name)</field>
|
||||
<field name="ai_tool_schema">
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"module_name": {
|
||||
"type": "string",
|
||||
"description": "Name of the module to check if it's installed."
|
||||
}
|
||||
},
|
||||
"required": ["module_name"]
|
||||
}
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="ir_actions_delete_campaign_step" model="ir.actions.server">
|
||||
<field name="name">AI Tool: Delete Step</field>
|
||||
<field name="ai_tool_name">ai_tool_delete_campaign_step</field>
|
||||
<field name="state">code</field>
|
||||
<field name="use_in_ai" eval="True"/>
|
||||
<field name="model_id" ref="ai_marketing_automation.model_ai_tool"/>
|
||||
<field name="ai_tool_thinking_text">Removing a campaign step.</field>
|
||||
<field name="ai_tool_description">Delete a step from a marketing campaign, repairing the surrounding workflow. This is the only supported way to remove a campaign activity.</field>
|
||||
<field name="code">ai['result'] = record._delete_campaign_step(activity_id, step_type, cascade_delete)</field>
|
||||
<field name="ai_tool_schema">
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"activity_id": {
|
||||
"type": "integer",
|
||||
"description": "ID of the marketing.activity whose step should be removed."
|
||||
},
|
||||
"step_type": {
|
||||
"type": "string",
|
||||
"description": "Which part of the node to remove. Use 'delay' to remove only the waiting period and keep the step itself, 'trigger' to remove the interaction node, or the activity's own type (email, action, split, log_note, subscribe_to_list, structure) to remove the activity."
|
||||
},
|
||||
"cascade_delete": {
|
||||
"type": "boolean",
|
||||
"description": "Send false for every step except the root. True is only for deleting the root activity (trigger_type 'begin'), which removes the entire campaign workflow and requires the user's explicit confirmation first. Always send this explicitly."
|
||||
}
|
||||
},
|
||||
"required": ["activity_id", "step_type", "cascade_delete"]
|
||||
}
|
||||
</field>
|
||||
</record>
|
||||
</odoo>
|
||||
5
ai_marketing_automation/models/__init__.py
Normal file
5
ai_marketing_automation/models/__init__.py
Normal file
@@ -0,0 +1,5 @@
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from . import ai_composer
|
||||
from . import ai_session
|
||||
from . import ai_tool
|
||||
27
ai_marketing_automation/models/ai_composer.py
Normal file
27
ai_marketing_automation/models/ai_composer.py
Normal file
@@ -0,0 +1,27 @@
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class AIComposer(models.Model):
|
||||
_inherit = 'ai.composer'
|
||||
|
||||
interface_key = fields.Selection(
|
||||
selection_add=[
|
||||
("campaign_builder_ai", "Create and edit a marketing campaign"),
|
||||
],
|
||||
ondelete={
|
||||
"campaign_builder_ai": "cascade",
|
||||
},
|
||||
)
|
||||
|
||||
@api.depends("interface_key")
|
||||
def _compute_hide_model_selection(self):
|
||||
super()._compute_hide_model_selection()
|
||||
for rule in self:
|
||||
rule.hide_model_selection = rule.hide_model_selection or rule.interface_key in ['campaign_builder_ai']
|
||||
|
||||
@api.depends("interface_key")
|
||||
def _compute_hide_prompt_button_page(self):
|
||||
super()._compute_hide_prompt_button_page()
|
||||
for rule in self:
|
||||
rule.hide_prompt_button_page = rule.hide_prompt_button_page or rule.interface_key in ['campaign_builder_ai']
|
||||
23
ai_marketing_automation/models/ai_session.py
Normal file
23
ai_marketing_automation/models/ai_session.py
Normal file
@@ -0,0 +1,23 @@
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import models
|
||||
|
||||
CAMPAIGN_BUILDER_TIMEOUT = 180
|
||||
|
||||
|
||||
class AiSession(models.Model):
|
||||
_inherit = 'ai.session'
|
||||
|
||||
def _get_model_round_options(self):
|
||||
completion_options = super()._get_model_round_options()
|
||||
if self._is_campaign_builder_session():
|
||||
completion_options['timeout'] = CAMPAIGN_BUILDER_TIMEOUT
|
||||
return completion_options
|
||||
|
||||
def _run_agentic_loop(self, *args, **kwargs):
|
||||
if self._is_campaign_builder_session():
|
||||
kwargs['timeout'] = CAMPAIGN_BUILDER_TIMEOUT
|
||||
yield from super()._run_agentic_loop(*args, **kwargs)
|
||||
|
||||
def _is_campaign_builder_session(self):
|
||||
return len(self) == 1 and self.ai_composer_id.interface_key == 'campaign_builder_ai'
|
||||
48
ai_marketing_automation/models/ai_tool.py
Normal file
48
ai_marketing_automation/models/ai_tool.py
Normal file
@@ -0,0 +1,48 @@
|
||||
from odoo import api, models
|
||||
|
||||
|
||||
class AITool(models.AbstractModel):
|
||||
_inherit = 'ai.tool'
|
||||
|
||||
@api.model
|
||||
def _sort_campaign_steps(self, campaign_id):
|
||||
campaign = self.env['marketing.campaign'].browse(campaign_id).exists()
|
||||
if not campaign:
|
||||
return {'success': False, 'error': f'No campaign with id {campaign_id}.'}
|
||||
campaign.action_sort_steps()
|
||||
return {'success': True, 'campaign_id': campaign.id}
|
||||
|
||||
@api.model
|
||||
def _is_module_installed(self, module_name):
|
||||
return {
|
||||
'module': module_name,
|
||||
'installed': module_name in self.env['ir.module.module']._installed(),
|
||||
}
|
||||
|
||||
@api.model
|
||||
def _delete_campaign_step(self, activity_id, step_type, cascade_delete=False):
|
||||
"""Remove a step from a campaign, repairing the workflow around it."""
|
||||
activity = self.env['marketing.activity'].browse(activity_id).exists()
|
||||
if not activity:
|
||||
return {'success': False, 'error': f'No marketing activity with id {activity_id}.'}
|
||||
|
||||
campaign = activity.campaign_id
|
||||
activity.action_delete_step(step_type)
|
||||
campaign.action_sort_steps()
|
||||
return {
|
||||
'success': True,
|
||||
'campaign_id': campaign.id,
|
||||
'remaining_activity_ids': campaign.marketing_activity_ids.ids,
|
||||
}
|
||||
|
||||
def _is_base_automation_server_action(self, tool_context):
|
||||
if tool_context.get('res_model') == 'marketing.campaign':
|
||||
return False
|
||||
|
||||
return super()._is_base_automation_server_action(tool_context)
|
||||
|
||||
def _is_automation_skill_required(self, tool_context):
|
||||
if tool_context.get('res_model') == 'marketing.campaign':
|
||||
return False
|
||||
|
||||
return super()._is_base_automation_server_action(tool_context)
|
||||
@@ -0,0 +1,3 @@
|
||||
.o_marketing_campaign_helper_card {
|
||||
width: 140px;
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
import { usePlugin } from "@odoo/owl";
|
||||
import { patch } from "@web/core/utils/patch";
|
||||
import { useService } from "@web/core/utils/hooks";
|
||||
import { _t } from "@web/core/l10n/translation";
|
||||
import { NotificationPlugin } from "@web/core/notifications/notification_plugin";
|
||||
import { CampaignFlowView } from "@marketing_automation/components/campaign_flow_view/campaign_flow_view";
|
||||
|
||||
patch(CampaignFlowView.prototype, {
|
||||
setup() {
|
||||
super.setup();
|
||||
this.notification = usePlugin(NotificationPlugin);
|
||||
this.launcher = useService("aiChatLauncher");
|
||||
},
|
||||
|
||||
async onAiChatClick() {
|
||||
if (!this.launcher) {
|
||||
this.notification.add(_t("AI service not available."), { type: "warning" });
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const [campaignId] = await this.orm.create("marketing.campaign", [
|
||||
{ title: _t("Campaign") },
|
||||
]);
|
||||
this.refresh({ resId: campaignId });
|
||||
const res = await this.launcher.launchAIChat({
|
||||
interfaceKey: "campaign_builder_ai",
|
||||
channelTitle: _t("AI Campaign Assistant"),
|
||||
recordModel: "marketing.campaign",
|
||||
recordId: campaignId,
|
||||
});
|
||||
console.log(res);
|
||||
} catch (e) {
|
||||
this.notification.add(_t("Failed to open AI chat."), { type: "danger" });
|
||||
console.error(e);
|
||||
}
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<templates>
|
||||
<t t-name="ai_marketing_automation.CampaignFlowViewAI" t-inherit="marketing_automation.CampaignFlowView" t-inherit-mode="extension">
|
||||
<xpath expr="//div[hasclass('o_marketing_helper_cards')]" position="inside">
|
||||
<span class="px-3">or</span>
|
||||
<div class="o_marketing_campaign_helper_card border rounded text-center cursor-pointer bg-white p-3 ps-4 pe-4"
|
||||
t-on-click="() => this.onAiChatClick()">
|
||||
<img src="/marketing_automation/static/img/ai.png" class="d-block mx-auto" width="64" height="64" alt="AI icon"/>
|
||||
<p class="m-0">Ask AI</p>
|
||||
</div>
|
||||
</xpath>
|
||||
</t>
|
||||
</templates>
|
||||
@@ -0,0 +1,20 @@
|
||||
import { patch } from "@web/core/utils/patch";
|
||||
import { _t } from "@web/core/l10n/translation";
|
||||
import SystrayAction from "@ai/web/systray_action";
|
||||
|
||||
patch(SystrayAction.prototype, {
|
||||
async onClickLaunchAIChat() {
|
||||
const controller = await this.actionService.currentController;
|
||||
const { resModel, resId } = controller?.props || {};
|
||||
if (resModel === "marketing.campaign") {
|
||||
this.aiChatLauncher.launchAIChat({
|
||||
interfaceKey: "campaign_builder_ai",
|
||||
channelTitle: _t("AI Campaign Assistant"),
|
||||
recordId: resId || false,
|
||||
recordModel: resId ? resModel : false,
|
||||
});
|
||||
return;
|
||||
}
|
||||
return super.onClickLaunchAIChat();
|
||||
},
|
||||
});
|
||||
1
ai_marketing_automation/tests/__init__.py
Normal file
1
ai_marketing_automation/tests/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import test_ai_marketing_campaign_builder
|
||||
@@ -0,0 +1,27 @@
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo.addons.marketing_automation.tests.common import MarketingAutomationCommon
|
||||
from odoo.addons.ai.tests.common import TestAICommon
|
||||
from odoo.tests import tagged, HttpCase
|
||||
|
||||
|
||||
@tagged("ai_marketing_automation")
|
||||
class TestAIMarketingCampaignBuilder(MarketingAutomationCommon, TestAICommon, HttpCase):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
cls.campaign_builder_agent = cls.env.ref('ai_marketing_automation.ai_agent_campaign_builder')
|
||||
|
||||
def _create_ai_campaign_builder_session(self):
|
||||
session_data = self.env['ai.agent'].action_launch_ai_chat(
|
||||
interface_key='campaign_builder_ai'
|
||||
)
|
||||
ai_session = self.env['ai.session'].search(
|
||||
[['channel_id', '=', session_data['ai_channel_id']]])
|
||||
return ai_session
|
||||
|
||||
def test_ai_campaign_initial_context(self):
|
||||
ai_session = self._create_ai_campaign_builder_session()
|
||||
self.assertEqual(ai_session.agent_id, self.campaign_builder_agent,
|
||||
"AI session should be launched with the Campaign Builder agent when using the 'campaign_builder_ai' interface key.")
|
||||
Reference in New Issue
Block a user