Create a department and hire an agent
Use the API to create a department, open a position from a job, put an agent in it and read its place back. Every step lists the expected result.
In the Console
You can do the same without code. You need the owner or admin role in the organization.
- Open Console → Organization → Org structure, click the “新建” (New, plus) button above the list on the left, and choose “新建部门” (New department). Pick where it hangs under “上级部门” (Parent department), type the department under “名称” (Name), and click “新建部门”. You get “已新建部门「…」”.
- Open Console → Organization → Jobs and click “新建职位” (New job). Fill “编码” (Code, for example
support-agent; it cannot be changed afterwards and stays taken after the job is retired) and “名称” (Name), pick “适用职级” (Levels) if needed, and click “新建职位”. - Back in “组织架构”, select the new department and click “开设岗位” (Open position). Under “岗位来源” (Source) choose “使用职位” (Use a job) and the job from step 2, or “只写名称” (Title only) and type a title. Leave “职级” and “汇报给” alone if you like; “数量” (Count) defaults to 1. Click “开设岗位”; you get “已开设岗位”.
- On the position click “任命” (Appoint), pick a member or an agent, choose “主岗” (main post) or “兼任” (concurrent), and click “任命”. The steps and messages are in Concurrent posts, replacing, transferring.
You will see: the position under the department, with the person or agent you appointed as its holder.
The rest of this page does the same through the API.
You need an API key of an organization owner or admin (see API keys) in the PRAXIS_API_KEY environment variable, plus curl and jq. Set PRAXIS_API_BASE to target another environment; the default is https://api.deepraxis.com. Every name below carries a docs-example prefix and a timestamp so reruns do not collide: a job code is unique in the organization and stays taken after the job is retired.
1. Create a department
Every organization has an automatically created root department; the new department hangs under it.
export BASE="${PRAXIS_API_BASE:-https://api.deepraxis.com}"export TAG=$(date +%s)ROOT_ID=$(curl --fail-with-body -sS "$BASE/workforce/v1/departments?status=active" \ -H "Authorization: Bearer $PRAXIS_API_KEY" | jq -er '.data[] | select(.parent_id == null) | .id')DEPT_JSON=$(curl --fail-with-body -sS -X POST "$BASE/workforce/v1/departments" \ -H "Authorization: Bearer $PRAXIS_API_KEY" \ -H "Content-Type: application/json" \ -d "$(jq -n --arg parent "$ROOT_ID" --arg name "docs-example-support-$TAG" '{parent_id: $parent, name: $name}')")export DEPT_ID=$(printf '%s' "$DEPT_JSON" | jq -er '.id')printf '%s\n' "$DEPT_JSON"Expected: HTTP 201 and a department with status active and head_position_id null; a new department has no head position.
2. Define a job
A job is the template for positions: opening a position copies duties and methods onto it.
JOB_JSON=$(curl --fail-with-body -sS -X POST "$BASE/workforce/v1/jobs" \ -H "Authorization: Bearer $PRAXIS_API_KEY" \ -H "Content-Type: application/json" \ -d "$(jq -n --arg code "docs-example-support-agent-$TAG" '{code: $code, name: "Support agent", duties: "Answer customer tickets within one working day.", methods: "Check the knowledge base first; escalate refunds to the department head."}')")export JOB_ID=$(printf '%s' "$JOB_JSON" | jq -er '.id')printf '%s\n' "$JOB_JSON"Expected: HTTP 201, revision 1, status active, level_ids an empty array.
3. Open a position
Open one vacant position in the department from the job. request_id is your own unique key: sending the same value again returns the first result and opens nothing more.
POSITIONS_JSON=$(curl --fail-with-body -sS -X POST "$BASE/workforce/v1/positions" \ -H "Authorization: Bearer $PRAXIS_API_KEY" \ -H "Content-Type: application/json" \ -d "$(jq -n --arg dept "$DEPT_ID" --arg job "$JOB_ID" --arg rid "docs-example-open-$TAG" '{department_id: $dept, job_id: $job, request_id: $rid}')")export POSITION_ID=$(printf '%s' "$POSITIONS_JSON" | jq -er '.data[0].id')printf '%s\n' "$POSITIONS_JSON"Expected: HTTP 201 with one position in data: number is 1, holder is null, title is the job name, and duties and methods are copies of the job’s text.
4. Hire an agent
The script first creates an agent, then seats it. The holder address is agent: plus the agent ID. A just-created agent may not be on the organization roster yet; hiring then returns 503 ACTOR_SYNCING, and the script waits 10 seconds and retries with the same request_id, which cannot seat anyone twice.
AGENT_JSON=$(curl --fail-with-body -sS -X POST "$BASE/agent/v1/agents" \ -H "Authorization: Bearer $PRAXIS_API_KEY" \ -H "Content-Type: application/json" \ -d '{"name": "docs-example-agent", "kind": "service", "model": "deepseek-flash", "system": "Answer briefly.", "tools": []}')export AGENT_ID=$(printf '%s' "$AGENT_JSON" | jq -er '.id')
HIRE_BODY=$(jq -n --arg actor "agent:$AGENT_ID" --arg rid "docs-example-hire-$TAG" '{candidate: {kind: "member", actor: $actor}, request_id: $rid}')HIRE_FILE=$(mktemp)for attempt in 1 2 3 4 5 6; do HTTP_STATUS=$(curl -sS -o "$HIRE_FILE" -w '%{http_code}' -X POST "$BASE/workforce/v1/positions/$POSITION_ID/hire" \ -H "Authorization: Bearer $PRAXIS_API_KEY" \ -H "Content-Type: application/json" \ -d "$HIRE_BODY") [ "$HTTP_STATUS" != "503" ] && break sleep 10doneecho "HTTP $HTTP_STATUS"cat "$HIRE_FILE"export ASSIGNMENT_ID=$(jq -er ".id" "$HIRE_FILE")Expected: HTTP 201, primary true (an actor’s first assignment becomes its primary) and end_time null.
5. Read it back
curl --fail-with-body -sS "$BASE/workforce/v1/positions/$POSITION_ID" \ -H "Authorization: Bearer $PRAXIS_API_KEY" | jq '{id, status, holder: .holder | {actor, name, kind, primary}}'
curl --fail-with-body -sS "$BASE/workforce/v1/actors/agent:$AGENT_ID" \ -H "Authorization: Bearer $PRAXIS_API_KEY" | jq '.primary | {title, department_path: [.department_path[].name], job: .job.name}'Expected: the position’s holder.kind is service and holder.primary is true; the agent’s primary position is titled Support agent and its department path runs from the root department to the new one.
The same with the SDK
The official @deepraxis/sdk exposes the methods under praxis.workforce.*.
import { Praxis } from '@deepraxis/sdk';
const praxis = new Praxis({ apiKey: process.env.PRAXIS_API_KEY!, baseUrl: process.env.PRAXIS_API_BASE ?? 'https://api.deepraxis.com',});
const tag = Date.now().toString(36); // job codes are unique in an organization; the suffix makes the script repeatable
// 1. Create a department under the rootconst departments = await praxis.workforce.departments.list({ query: { status: 'active' } });const root = departments.data.find(d => d.parent_id === null)!;const department = await praxis.workforce.departments.create({ body: { parent_id: root.id, name: `docs-example-support-${tag}` },});
// 2. Define a job (the template)const job = await praxis.workforce.jobs.create({ body: { code: `docs-example-support-agent-${tag}`, name: 'Support agent', duties: 'Answer customer tickets within one working day.', methods: 'Check the knowledge base first; escalate refunds to the department head.', },});
// 3. Open a position from the jobconst opened = await praxis.workforce.positions.create({ body: { department_id: department.id, job_id: job.id, request_id: `docs-example-open-${tag}` },});const position = opened.data[0]!;
// 4. Hire an agentconst agent = await praxis.agent.agents.create({ body: { name: 'docs-example-agent', kind: 'service', model: 'deepseek-flash', system: 'Answer briefly.', tools: [] },});const actor = `agent:${agent.id}`;// A new agent may not be on the roster yet: 503 ACTOR_SYNCING. Wait, then retry with the same request_idasync function hire() { for (let attempt = 0; ; attempt++) { try { return await praxis.workforce.positions.hire.create({ path: { id: position.id }, body: { candidate: { kind: 'member', actor }, request_id: `docs-example-hire-${tag}` }, }); } catch (error) { if ((error as { code?: string }).code !== 'ACTOR_SYNCING' || attempt >= 5) throw error; await new Promise(resolve => setTimeout(resolve, 10_000)); } }}const assignment = await hire();console.log(assignment.id, assignment.primary);
// 5. Read it backconst seat = await praxis.workforce.positions.retrieve({ path: { id: position.id } });console.log(seat.holder?.actor, seat.holder?.kind);const where = await praxis.workforce.actors.retrieve({ path: { actor } });console.log(where.primary?.title, where.primary?.department_path.map(d => d.name));Clean up
End the assignment and close the position before dissolving the department; a dissolved department and a retired job stay as history, and a retired job opens no more positions.
curl --fail-with-body -sS -X POST "$BASE/workforce/v1/assignments/$ASSIGNMENT_ID/terminate" \ -H "Authorization: Bearer $PRAXIS_API_KEY" \ -H "Content-Type: application/json" \ -d '{"reason": "retired"}'
curl --fail-with-body -sS -X POST "$BASE/workforce/v1/positions/$POSITION_ID/close" \ -H "Authorization: Bearer $PRAXIS_API_KEY"
curl --fail-with-body -sS -X POST "$BASE/workforce/v1/departments/$DEPT_ID/dissolve" \ -H "Authorization: Bearer $PRAXIS_API_KEY"
curl --fail-with-body -sS -X POST "$BASE/workforce/v1/jobs/$JOB_ID/retire" \ -H "Authorization: Bearer $PRAXIS_API_KEY"
curl --fail-with-body -sS -X POST "$BASE/agent/v1/agents/$AGENT_ID/archive" \ -H "Authorization: Bearer $PRAXIS_API_KEY"Expected: every request returns HTTP 200. Ending the assignment leaves the position vacant; only a vacant position can be closed; dissolving needs a department with no active sub-department and no unclosed position, otherwise 409 DEPARTMENT_NOT_EMPTY.
Concurrent positions, replacing and transfers → · Set objectives → · Limits and errors →