Using Agent Builder to Suggest Optimal Posting Times and Route Posts for Approval

Using Agent Builder to Suggest Optimal Posting Times and Route Posts for Approval

This agent watches for new posts your team drafts, recommends a publish time based on each profile's calendar, and sends the scheduled post into your existing approval workflow. Your organic team reviews a suggested time instead of picking one by hand.

The agent handles two things at once:

  • Timing — a sensible hour on a weekday, based on per-network best practice (for example, Tue to Thu mornings on LinkedIn).
  • Spacing — at least four hours from any other post already scheduled on that same profile.

The post is never published automatically. It only gets a suggested time and a trip through your approval workflow. A person still makes the final call.

Prerequisites

  • At least one Approval Workflow already set up (Compliance > Workflows)
  • A connected social profile with some posting history, so the agent has something to schedule around
  • Your account timezone from Settings > Account. You name it explicitly in Step 3

How It Works

The agent is five nodes, run in order every time a new post is created:

Node Type What it does
Post Created Event trigger Starts the agent whenever someone creates a new post
Queued Equals "0" Filter Only lets unscheduled drafts through (see the note in Step 2)
AI Action AI Action Reads the post and profile calendar, decides on a time
update_post Oktopost Action Writes that time onto the draft
send_to_workflow Oktopost Action Submits the now-scheduled post to your approval workflow

Configure the Agent

Step 1: Create the Agent and Trigger

  1. Go to AI Management > Custom Agents.
  2. Click New Agent and name it (for example, Posting-Time Agent).
  3. Add an Event node as the first step.
  4. Set Event Type to Post Created, under the Publishing category.

Step 2: Filter Out Already-Scheduled Posts

  1. Add a Filter node connected to the trigger's Yes output.
  2. Set the field to Queued.
  3. Set the operator to Equals and the value to 0.

The Queued field returns 0, not a true empty value, on a brand-new draft. If you filter on "Is Empty" instead, the agent will never fire.

Step 3: Configure the AI Action Node

  1. Add an AI Action node connected to the filter's Yes output.
  2. Set Permissions to Read only. This node should only recommend a time, never write it directly.
  3. Set Model to Thinking. Working out a Unix timestamp is exact arithmetic, and Thinking is noticeably more reliable at it than Fast.
  4. In Instructions, paste the prompt below. Swap in your account's real timezone, and use your agent's variable picker to re-insert the trigger's Id, ProfileIds, and CampaignId in place of the placeholder tokens.
  5. Under Response Fields, add three fields: recommendedTime (Number), rationale (String), spacingConflict (Boolean).

AI prompt:

Trigger data:
Post ID: {{nodes.<EVENT_NODE_ID>.output.Id}}
Profile IDs: {{nodes.<EVENT_NODE_ID>.output.ProfileIds}}
Network: {{nodes.<EVENT_NODE_ID>.output.Network}}

This post has no scheduled time yet. Your only job is to recommend one. Do not change the post yourself, do not publish it, and do not approve it. A later step in this agent writes your recommendation to the post.

This account's timezone is [YOUR TIMEZONE, e.g. Asia/Jerusalem]. Every time you reason about (business hours, best-practice slots, the recommended time itself) is in that local time. Do not guess or infer this timezone from other data — use it directly, and account for its current UTC offset when you convert your chosen local date and time into a Unix timestamp. Show your conversion step to yourself before finalizing the number, so you do not output a timestamp that actually falls outside the hours you intended.

Keep your research minimal and fast. Do exactly these two lookups, nothing else:
1. Call get_post once (using the Id above) to confirm this post's Network. You do not need the message body, the social profile details, or historical engagement data — none of that is needed for this decision, and fetching it only slows things down.
2. Call get_calendar once for this profile (ProfileIds), scoped ONLY to a forward-looking window: from today through 14 days from now. Never request a past date range, and never request more than 14 days out. When you compare your candidate time to any other post get_calendar returns, compare using StartDateTimeUTC on both sides so a timezone mismatch cannot produce a wrong comparison.

Then, using only what those two calls returned, pick a recommended date and time that: falls on a weekday, within the account's business hours (roughly 9am to 6pm local); is at least 4 hours apart from any other post already scheduled on that profile within that 14-day window; and is at most 14 days from now. Use a documented per-network best-practice slot as your baseline (for example, LinkedIn: Tuesday to Thursday, 9 to 11am local time), adjusted only as needed to satisfy the spacing rule.

Write a one-sentence rationale for the chosen time, stated in local time.

Before you finalize your answer, convert recommendedTime back to a calendar date and time in your account's timezone and confirm it matches the exact date and time you stated in your rationale (same day of week, same date, same hour). If they do not match, you made an arithmetic error — recompute recommendedTime and check again before responding. Pay particular attention when your chosen date crosses into a new month; that is where this kind of error happens most often.

Return exactly these response fields: recommendedTime as a Unix timestamp in whole seconds since epoch (a Number, not a string), computed as described above; rationale as the one-sentence explanation; spacingConflict as true only if you could not fully satisfy the minimum-spacing rule and had to pick a compromise time, otherwise false.

Step 4: Write the Recommended Time to the Post

  1. Add an Oktopost Action node connected to the AI Action's output.
  2. Set Tool to update_post.
  3. Set postId to the trigger's Id.
  4. Set startDateTime to the AI Action's recommendedTime response field.
  5. Set status to pending.

Step 5: Route the Post to Approval

  1. Add a second Oktopost Action node connected to the previous node's output.
  2. Set Tool to send_to_workflow.
  3. Set entityId to the trigger's Id.
  4. Set workflowId to the approval workflow your organic team already reviews from.

Step 6: Save, Test, and Activate

  1. Click Save to keep the agent in Draft while you test.
  2. Create a real draft post on a connected profile and confirm a new run appears under Runs.
  3. Open the run and check that update_post and send_to_workflow both show Completed.
  4. Click Set Active once you are satisfied with a few clean test runs.

What Your Team Sees

Once the agent is active, nothing changes about how someone creates a post. The only difference is that it shows up in the approval queue already scheduled, instead of sitting unscheduled until someone picks a time.

In Approvals, the reviewer sees the post with its suggested date and time filled in. Approving it schedules it for real, at that time. Rejecting it sends it back to drafts, where it is picked up and re-evaluated the next time the agent runs.

Troubleshooting

Symptom Likely cause Fix
Agent never runs Filter checking "Queued Is Empty" Use "Queued Equals 0" instead. See Step 2
Post lands at the wrong hour, or the write-up and the actual time disagree AI Action guessed the timezone, or made an arithmetic slip converting to a timestamp Name the timezone explicitly and add the self-check step. See Step 3
update_post fails with a permissions error The post is already tied to a workflow from an earlier test Oktopost locks a post from direct edits once it has been submitted to a workflow. Test with a fresh post each time
Was this article helpful?
0 out of 0 found this helpful