CypherMonkeyAI omni-channel lab

A lifelong-learner lab on AI omni-channel agents, including voice and the contact center. Free to read. Nothing sold.

Programming foundations · L1 · 20 min

Python values and functions

Learn in five minutes

  • A function takes an input and returns an output.
  • Strings, numbers, lists, and dicts cover the labs.
  • A pure function is easier to test than a hidden global.
  • Name the unit: tokens, milliseconds, or documents.
  • Print the value and the unit together.

Agent code fails when a function both computes and secretly sends data. Split the calculation from the side effect so a test can call the calculation alone.

This section HTML

Visual

T1-R3 diagram

Diagram SVGDiagram PNGDiagram HTML

A toy token counter

  1. Define a function that splits on spaces. Label it a toy, not a real tokenizer.
  2. Assert that 'red fox' returns 2.
  3. Pass an empty string and expect 0, not a crash.

This section HTML

Quiz

Why label the counter a toy?

Space-splitting is not a model tokenizer.

What should a test call?

A known input makes the expected output checkable.

What belongs next to a number?

Tokens, milliseconds, and documents are different units.

This section HTML

Ecosystem

Pure function
Same input, same output, no hidden write.

Sisters: Git, HTTP, JSON, unit tests.

A Python script can later call a local runner or a cloud API with the same JSON shape.

The same notebook becomes the capstone log.

Config

  • Write the goal in one sentence.
  • Name the input and the allowed output.
  • Save the trace next to the result.

Troubleshooting

  • The answer looks fluent and is wrong. Check whether a source passage actually contains the claim.
  • The loop never stops. Set a step cap and stop when the tool result repeats.

This section HTML

Sources HTML

Sources and go deeper

sources.json