import { CodeTabs } from '../views/docs/CodeTabs';
import { Callout, NextLink } from '../views/docs/prose';
export const GET_FIELD_SIG_PY = `def get_field(field_key: str) -> str | int | dict | None`;

export const GET_FIELD_SIG_TS = `getField(key: string): Promise<any | null>`;

export const GET_FIELD_EX_PY = `@agent.on_task_complete("schedule_appointment")
def on_appointment_scheduled(call: guava.Call):
    appointment_time = call.get_field("appointment_time")
    patient_name = call.get_field("patient_name")
    # Write to your CRM / EHR
    save_appointment(patient_name, appointment_time)
    call.hangup()`;

export const GET_FIELD_EX_TS = `agent.onTaskComplete("schedule_appointment", async (call: guava.Call) => {
  const appointmentTime = await call.getField("appointment_time");
  const patientName = await call.getField("patient_name");
  // Write to your CRM / EHR
  saveAppointment(patientName, appointmentTime);
  await call.hangup();
})`;

## get_field()

After the checklist completes and `agent.on_task_complete` fires, use `call.get_field()` to retrieve collected values by their key. This is where you write results to your CRM, database, or EHR.

<CodeTabs
  python={{ code: GET_FIELD_SIG_PY, filename: "signature" }}
  typescript={{ code: GET_FIELD_SIG_TS, filename: "signature" }}
/>

<CodeTabs
  python={{ code: GET_FIELD_EX_PY, filename: "example.py" }}
  typescript={{ code: GET_FIELD_EX_TS, filename: "example.ts" }}
/>

### Return types by field type

The type of the value returned by `get_field()` depends on the field's `field_type`:

| `field_type` | Returned value |
|---|---|
| `text` | `str` |
| `date` | `dict` with keys `year`, `month`, `day` (all `int`) |
| `integer` | `int` |
| `multiple_choice` | `str` (guaranteed to be one of the values in `choices` or returned by `choice_generator`) |
| `calendar_slot` | ISO-8601 datetime string (e.g. `"2022-12-25T16:30"`) |

<Callout>
  <span className="text-primary font-semibold">Tip:</span> You can call `get_field()` at any point after the field has been collected — not just in `on_task_complete`. Use it in mid-call callbacks to personalize subsequent steps.
</Callout>

<NextLink section="intent-recognizer" label="IntentRecognizer" />
